#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define int long long
#define DISABLE_PRINTF
#ifdef DISABLE_PRINTF
#define printf(...)
#endif // DISABLE_PRINTF
using namespace std;
void solve()
{
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
for(int i = 1; i <= n; ++i)
{
cin >> a[i] >> b[i];
}
/// solve it
int ans = 0;
int aid = 1, bid = 1;
for(; bid <= n; ++bid)
{
for(; b[bid] > 0; ++aid)
{
int take = min(a[aid], b[bid]);
b[bid] -= take;
a[aid] -= take;
ans += take * abs(bid - aid);
if(b[bid] == 0)
{
break;
}
}
}
cout<<ans;
}
signed main()
{
#ifdef EVAL
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
#endif // EVAL
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
1364 KB |
Output is correct |
5 |
Correct |
14 ms |
2516 KB |
Output is correct |
6 |
Correct |
42 ms |
7604 KB |
Output is correct |
7 |
Correct |
88 ms |
14780 KB |
Output is correct |
8 |
Correct |
66 ms |
13000 KB |
Output is correct |
9 |
Correct |
71 ms |
12348 KB |
Output is correct |
10 |
Correct |
51 ms |
10060 KB |
Output is correct |
11 |
Correct |
48 ms |
10052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Correct |
8 ms |
1364 KB |
Output is correct |
5 |
Correct |
14 ms |
2516 KB |
Output is correct |
6 |
Correct |
42 ms |
7604 KB |
Output is correct |
7 |
Correct |
88 ms |
14780 KB |
Output is correct |
8 |
Correct |
66 ms |
13000 KB |
Output is correct |
9 |
Correct |
71 ms |
12348 KB |
Output is correct |
10 |
Correct |
51 ms |
10060 KB |
Output is correct |
11 |
Correct |
48 ms |
10052 KB |
Output is correct |
12 |
Incorrect |
21 ms |
3912 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |