#include <iostream>
#include <cmath>
int a[500005], b[500005], d[500005];
using namespace std;
long long solve(int n)
{
for (int i=1; i<=n; i++)
d[i]=a[i]-b[i];
long long ans=0;
for (int i=1; i<=n-1; i++)
if (d[i])
{
ans+=abs(d[i]);
d[i+1]+=d[i];
d[i] = 0;
}
return ans;
}
int main()
{
int n;
cin>>n;
for (int i=1; i<=n; i++)
cin>>a[i]>>b[i];
cout<<solve(n);
return 0;
}
# | 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... |