fork download
  1. using static IO;
  2. public class IO
  3. {
  4. public static IO Cin = new();
  5. public static StreamReader reader = new(Console.OpenStandardInput());
  6. public static StreamWriter writer = new(Console.OpenStandardOutput());
  7. public static implicit operator string(IO _) => reader.ReadLine();
  8. public static implicit operator char[](IO _) => reader.ReadLine().ToArray();
  9. public static implicit operator int(IO _) => int.Parse(reader.ReadLine());
  10. public static implicit operator double(IO _) => double.Parse(reader.ReadLine());
  11. public static implicit operator double[](IO _) => reader.ReadLine().Split().Select(double.Parse).ToArray();
  12. public static implicit operator int[](IO _) => Array.ConvertAll(reader.ReadLine().Split(), int.Parse);
  13. public void Deconstruct(out int a, out int b) { int[] r = Cin; (a, b) = (r[0], r[1]); }
  14. public void Deconstruct(out int a, out int b, out int c) { int[] r = Cin; (a, b, c) = (r[0], r[1], r[2]); }
  15. public static object? Cout { set { writer.Write(value); } }
  16. public static object? Coutln { set { writer.WriteLine(value); } }
  17. public static void Main() { Program.Coding(); writer.Flush(); }
  18. }
  19. class Program
  20. {
  21. public static void Coding()
  22. {
  23. int n = Cin;
  24. double[] books = Cin;
  25. int[] weights = Cin;
  26.  
  27. int[] dp = new int[n];
  28. for (int x = 0; x < n; x++)
  29. {
  30. ref int me = ref dp[x];
  31. me = weights[x];
  32.  
  33. for (int y = 0; y < x; y++)
  34. {
  35. if (books[y] > books[x]) continue;
  36. me = Math.Max(me, weights[x] + dp[y]);
  37. }
  38. }
  39.  
  40. Cout = weights.Sum() - dp.Max();
  41. }
  42. }
Success #stdin #stdout 0.08s 30992KB
stdin
9
813.8 812 816 813 811 813 813.6 801.9 880.1
6 20 5 8 17 20 12 41 6
stdout
69