#pragma GCC target ("avx2")
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;
const int MAXN = 500100, MAXK = 30;
//const ll MOD = 998244353;
const ll INF = 4e18;
const ld PI = asin(1) * 2;
int n;
ll a[MAXN], b[MAXN], dif[MAXN], pref[MAXN];
ll dp[3100][31000];
int main()
{
FAST_IO;
cin >> n;
FOR(i, 1, n) cin >> a[i] >> b[i];
FOR(i, 1, n) {
dif[i] = a[i]-b[i];
pref[i] = pref[i-1] + dif[i];
}
ll mx = pref[n];
FOR(i, 1, n) FOR(j, 0, mx) {
if (j > 0) dp[i][j] = dp[i][j-1];
else dp[i][j] = INF;
dp[i][j] = min(dp[i][j], dp[i-1][j] + abs(j - pref[i]));
}
cout << dp[n][mx] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
7 ms |
13772 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Runtime error |
87 ms |
26184 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
7 ms |
13772 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Runtime error |
87 ms |
26184 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
7 ms |
13772 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
16 ms |
20516 KB |
Output is correct |
5 |
Correct |
55 ms |
65624 KB |
Output is correct |
6 |
Runtime error |
239 ms |
262148 KB |
Execution killed with signal 9 |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
7 ms |
13772 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
16 ms |
20516 KB |
Output is correct |
6 |
Correct |
55 ms |
65624 KB |
Output is correct |
7 |
Runtime error |
239 ms |
262148 KB |
Execution killed with signal 9 |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
7 ms |
13772 KB |
Output is correct |
3 |
Correct |
7 ms |
13900 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
16 ms |
20516 KB |
Output is correct |
6 |
Correct |
55 ms |
65624 KB |
Output is correct |
7 |
Runtime error |
239 ms |
262148 KB |
Execution killed with signal 9 |
8 |
Halted |
0 ms |
0 KB |
- |