Submission #895102

# Submission time Handle Problem Language Result Execution time Memory
895102 2023-12-29T12:25:06 Z d4xn Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
5 ms 10584 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
const int N = 1e6+6, A = 1e6+6, inf = LLONG_MAX;
 
int n, a[N], b[N], x[A], y[A], dp[2][A];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
 
  cin >> n;
  int l1 = 0;
  int l2 = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    for (int j = 0; j < b[i]-a[i]; j++) {
      x[l1++] = i;
    }
    for (int j = 0; j < a[i]-b[i]; j++) {
      y[l2++] = i;
    }
  }

  for (int i = 0; i < l1; i++) {
    for (int j = i; j < l2; j++) {
      dp[i%2][j] = min(abs(x[i] - y[j]) + (i ? dp[(i-1)%2][j-1] : 0), (j > i ? dp[i%2][j-1] : inf));
    }
  }
  cout << dp[(l1-1)%2][l2-1] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Runtime error 5 ms 8796 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Runtime error 5 ms 8796 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Runtime error 5 ms 8796 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Runtime error 5 ms 8796 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 10584 KB Output is correct
2 Runtime error 5 ms 8796 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -