This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |