Submission #895106

#TimeUsernameProblemLanguageResultExecution timeMemory
895106d4xnPotatoes and fertilizers (LMIO19_bulves)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 3e3+3, A = 3e4+4, 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][j] = min(abs(x[i] - y[j]) + (i ? dp[(i-1)][j-1] : 0), (j > i ? dp[i][j-1] : inf)); } } cout << dp[(l1-1)][l2-1] << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...