#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define ii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define F0R(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define inf 1000000010
int dp[2][30001];
int diff[3000];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n; assert(n <= 3000);
ll totA = 0, totB = 0;
F0R(i, n) {
int a, b; cin >> a >> b;
totA += a; totB += b;
diff[i] = totA - totB;
}
assert(totA <= 30000 && totB <= 30000);
F0R(i, n) {
F0R(j, 30001) {
dp[i%2][j] = min((i>0 ? dp[(i-1)%2][j] : 0) + abs(diff[i]-j), (j>0 ? dp[i%2][j-1] : inf));
}
}
cout << dp[(n-1)%2][diff[n-1]] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
339 ms |
620 KB |
Output is correct |
3 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
339 ms |
620 KB |
Output is correct |
3 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
339 ms |
620 KB |
Output is correct |
3 |
Correct |
1 ms |
620 KB |
Output is correct |
4 |
Correct |
115 ms |
748 KB |
Output is correct |
5 |
Correct |
171 ms |
748 KB |
Output is correct |
6 |
Correct |
339 ms |
620 KB |
Output is correct |
7 |
Correct |
355 ms |
620 KB |
Output is correct |
8 |
Correct |
347 ms |
620 KB |
Output is correct |
9 |
Correct |
341 ms |
748 KB |
Output is correct |
10 |
Correct |
344 ms |
620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
339 ms |
620 KB |
Output is correct |
3 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
620 KB |
Output is correct |
2 |
Correct |
339 ms |
620 KB |
Output is correct |
3 |
Runtime error |
2 ms |
620 KB |
Execution killed with signal 6 (could be triggered by violating memory limits) |