#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long double ld;
typedef pair<ld, ld> pld;
typedef pair<lli, lli> pll;
#define mp(x, y) make_pair(x, y)
const lli MAXN = 5e5+5;
lli N;
lli a[MAXN], b[MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> N;
for (lli i = 0; i < N; i++) cin >> a[i] >> b[i];
lli c[N];
for (lli i = 0; i < N; i++) c[i] = a[i] - b[i];
lli ans = 0;
for (lli j = 1; j < N; j++) {
for (lli i = 0; i < N-j; i++) {
if (c[i] > 0 && c[i+j] < 0) {
lli val = min(c[i], -c[i+j]);
ans += j*val;
c[i] -= val;
c[i+j] += val;
}
}
for (lli i = N-j-1; i >= 0; i--) {
if (c[i] < 0 && c[i+j] > 0) {
lli val = min(-c[i], c[i+j]);
ans += j*val;
c[i] += val;
c[i+j] -= val;
}
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
7 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
7 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
7 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
7 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
7 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |