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 <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
int main()
{
int n;
cin>>n;
vector<int> v;
vector<int> sum;
for(int i=0; i<n; i++)
{
int a,b;
cin>>a>>b;
v.push_back(a-b);
if(i>0)
sum.push_back(sum[sum.size()-1]+a-b);
else
sum.push_back(a-b);
}
int ile=0;
int res=0;
for(int i=0; i<n; i++)
{
ile+=v[i];
if(ile<=0)
res-=ile;
else if(sum[sum.size()-1]-sum[i]<0)
res-=sum[sum.size()-1]-sum[i];
}
cout<<res;
}
# | 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... |