#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 |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Incorrect |
24 ms |
1116 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Incorrect |
24 ms |
1116 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Incorrect |
0 ms |
216 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
216 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
216 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |