#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=5e5+5;
ll n, a[nx], b[nx], ans;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n;
for (int i=1; i<=n; i++) cin>>a[i]>>b[i];
int i=1, j=1;
while (i<=n&&j<=n)
{
int mn=min(a[i], b[j]);
a[i]-=mn;
b[j]-=mn;
ans+=mn*abs(i-j);
if (a[i]==0) i++;
if (b[j]==0) j++;
}
cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
6 ms |
6916 KB |
Output is correct |
5 |
Correct |
11 ms |
7256 KB |
Output is correct |
6 |
Correct |
34 ms |
10076 KB |
Output is correct |
7 |
Correct |
68 ms |
14968 KB |
Output is correct |
8 |
Incorrect |
53 ms |
13140 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
6 ms |
6916 KB |
Output is correct |
5 |
Correct |
11 ms |
7256 KB |
Output is correct |
6 |
Correct |
34 ms |
10076 KB |
Output is correct |
7 |
Correct |
68 ms |
14968 KB |
Output is correct |
8 |
Incorrect |
53 ms |
13140 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |