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 int(IO _) => int.Parse(reader.ReadLine().Trim());
  8. public static implicit operator double[](IO _) => reader.ReadLine().Split(' ',StringSplitOptions.RemoveEmptyEntries).Select(double.Parse).ToArray();
  9. public static implicit operator int[](IO _) => Array.ConvertAll(reader.ReadLine().Split(' ',StringSplitOptions.RemoveEmptyEntries), int.Parse);
  10. public void Deconstruct(out int a, out int b) { int[] r = Cin; (a, b) = (r[0], r[1]); }
  11. public void Deconstruct(out int a, out int b, out int c) { int[] r = Cin; (a, b, c) = (r[0], r[1], r[2]); }
  12. public static object? Cout { set { writer.Write(value); } }
  13. public static object? Coutln { set { writer.WriteLine(value); } }
  14. public static void Main() { Program.Coding(); writer.Flush(); }
  15. }
  16. class Program
  17. {
  18. public static void Coding()
  19. {
  20. int n = Cin;
  21. double[] books = Cin;
  22. int[] weights = Cin;
  23.  
  24. int[] dp = new int[n];
  25. for (int x = 0; x < n; x++)
  26. {
  27. ref int me = ref dp[x];
  28. me = weights[x];
  29.  
  30. for (int y = 0; y < x; y++)
  31. {
  32. if (books[y] > books[x]) continue;
  33. me = Math.Max(me, weights[x] + dp[y]);
  34. }
  35. }
  36.  
  37. Cout = weights.Sum() - dp.Max();
  38. }
  39. }
Success #stdin #stdout 0.09s 31000KB
stdin
3
802.11 813.1 107
4 5 6
stdout
6