#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using vll = vector<ll>;
int main()
{
int N;
cin >> N;
vll A(1+N), B(1+N);
ll totA = 0, totB = 0;
for(int i = 1; i <= N; i++)
{
cin >> A[i] >> B[i];
totA += A[i];
totB += B[i];
}
A[0] = B[0] = 0;
ll res = 0;
ll currA = 0, currB = 0;
for(int b = 1; b < N; b++)
{
currA += A[b];
currB += B[b];
if(currA < currB) res += currB - currA;
if((totA - currA) < (totB - currB)) res += (totB - currB) - (totA - currA);
}
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
1328 KB |
Output is correct |
5 |
Correct |
35 ms |
2372 KB |
Output is correct |
6 |
Correct |
144 ms |
7528 KB |
Output is correct |
7 |
Correct |
270 ms |
14764 KB |
Output is correct |
8 |
Correct |
263 ms |
12960 KB |
Output is correct |
9 |
Correct |
212 ms |
12332 KB |
Output is correct |
10 |
Correct |
144 ms |
10020 KB |
Output is correct |
11 |
Correct |
146 ms |
10052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
1328 KB |
Output is correct |
5 |
Correct |
35 ms |
2372 KB |
Output is correct |
6 |
Correct |
144 ms |
7528 KB |
Output is correct |
7 |
Correct |
270 ms |
14764 KB |
Output is correct |
8 |
Correct |
263 ms |
12960 KB |
Output is correct |
9 |
Correct |
212 ms |
12332 KB |
Output is correct |
10 |
Correct |
144 ms |
10020 KB |
Output is correct |
11 |
Correct |
146 ms |
10052 KB |
Output is correct |
12 |
Incorrect |
69 ms |
3884 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
288 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |