#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<long long>odp1(n);
priority_queue<long long,vector<long long>,greater<long long>>odp2;
for(auto &x : odp1)
{
int a,b;
cin>>a>>b;
x=(a-b);
odp2.push(0);
}
partial_sum(odp1.begin(),odp1.end(),odp1.begin());
odp2.push(0);
odp2.push(0);
long long punkty=0;
for(auto x : odp1 )
{
odp2.pop();
punkty+=max(-x-odp2.top(),0LL);
odp2.push(-x);
odp2.push(-x);
}
long long wi=0;
while(odp2.top()!=-odp1.back())
{
auto m=odp2.top();
odp2.pop();
punkty+=wi*(odp2.top()-m);
wi++;
}
cout<<punkty;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
32 ms |
1812 KB |
Output is correct |
5 |
Correct |
74 ms |
3868 KB |
Output is correct |
6 |
Correct |
243 ms |
9544 KB |
Output is correct |
7 |
Correct |
413 ms |
15572 KB |
Output is correct |
8 |
Correct |
399 ms |
15560 KB |
Output is correct |
9 |
Correct |
340 ms |
15988 KB |
Output is correct |
10 |
Correct |
270 ms |
14468 KB |
Output is correct |
11 |
Correct |
259 ms |
14400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
32 ms |
1812 KB |
Output is correct |
5 |
Correct |
74 ms |
3868 KB |
Output is correct |
6 |
Correct |
243 ms |
9544 KB |
Output is correct |
7 |
Correct |
413 ms |
15572 KB |
Output is correct |
8 |
Correct |
399 ms |
15560 KB |
Output is correct |
9 |
Correct |
340 ms |
15988 KB |
Output is correct |
10 |
Correct |
270 ms |
14468 KB |
Output is correct |
11 |
Correct |
259 ms |
14400 KB |
Output is correct |
12 |
Correct |
126 ms |
5048 KB |
Output is correct |
13 |
Correct |
280 ms |
12724 KB |
Output is correct |
14 |
Correct |
404 ms |
14368 KB |
Output is correct |
15 |
Correct |
404 ms |
14296 KB |
Output is correct |
16 |
Correct |
399 ms |
14348 KB |
Output is correct |
17 |
Correct |
231 ms |
14316 KB |
Output is correct |
18 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
2 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
332 KB |
Output is correct |
13 |
Correct |
4 ms |
332 KB |
Output is correct |
14 |
Correct |
3 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
3 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
3 ms |
332 KB |
Output is correct |
3 |
Correct |
4 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
2 ms |
332 KB |
Output is correct |
8 |
Correct |
2 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
32 ms |
1812 KB |
Output is correct |
12 |
Correct |
74 ms |
3868 KB |
Output is correct |
13 |
Correct |
243 ms |
9544 KB |
Output is correct |
14 |
Correct |
413 ms |
15572 KB |
Output is correct |
15 |
Correct |
399 ms |
15560 KB |
Output is correct |
16 |
Correct |
340 ms |
15988 KB |
Output is correct |
17 |
Correct |
270 ms |
14468 KB |
Output is correct |
18 |
Correct |
259 ms |
14400 KB |
Output is correct |
19 |
Correct |
126 ms |
5048 KB |
Output is correct |
20 |
Correct |
280 ms |
12724 KB |
Output is correct |
21 |
Correct |
404 ms |
14368 KB |
Output is correct |
22 |
Correct |
404 ms |
14296 KB |
Output is correct |
23 |
Correct |
399 ms |
14348 KB |
Output is correct |
24 |
Correct |
231 ms |
14316 KB |
Output is correct |
25 |
Correct |
2 ms |
332 KB |
Output is correct |
26 |
Correct |
4 ms |
332 KB |
Output is correct |
27 |
Correct |
3 ms |
332 KB |
Output is correct |
28 |
Correct |
3 ms |
332 KB |
Output is correct |
29 |
Correct |
3 ms |
460 KB |
Output is correct |
30 |
Correct |
3 ms |
332 KB |
Output is correct |
31 |
Correct |
3 ms |
460 KB |
Output is correct |
32 |
Correct |
2 ms |
332 KB |
Output is correct |
33 |
Correct |
141 ms |
5068 KB |
Output is correct |
34 |
Correct |
268 ms |
12684 KB |
Output is correct |
35 |
Correct |
403 ms |
14268 KB |
Output is correct |
36 |
Correct |
412 ms |
14380 KB |
Output is correct |
37 |
Correct |
386 ms |
14256 KB |
Output is correct |
38 |
Correct |
479 ms |
14324 KB |
Output is correct |
39 |
Correct |
289 ms |
14252 KB |
Output is correct |
40 |
Correct |
312 ms |
13860 KB |
Output is correct |
41 |
Correct |
271 ms |
14304 KB |
Output is correct |
42 |
Correct |
259 ms |
14236 KB |
Output is correct |
43 |
Correct |
240 ms |
14232 KB |
Output is correct |
44 |
Correct |
246 ms |
14252 KB |
Output is correct |
45 |
Correct |
448 ms |
14288 KB |
Output is correct |
46 |
Correct |
267 ms |
14284 KB |
Output is correct |
47 |
Correct |
241 ms |
13452 KB |
Output is correct |