#include<bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int N; cin>>N;
vector<long long> t(N);
for(int i = 0; i < N; i++){
int a, b; cin>>a>>b;
t[i] = a - b;
}
priority_queue<long long, vector<long long>, greater<long long>> q;
for(int i = 0; i < N; i++)q.push(0);
long long shift = 0;
long long val = 0;
for(int i = 1; i <= N; i++){
//wywalamy pierwszy punkt
q.pop();
//przesuwamy
shift += t[i-1];
//pobieramy pozycje pierwszego punktu
long long x = q.top() + shift;
if(x <= 0){
val += abs(x);
q.push(-shift); q.push(-shift);
}else{
q.push(-shift); q.push(-shift);
}
}
long long x = q.top() + shift;
long long result;
if(x >= 0){
result = val + x;
}else{
result = val;
int slope = 0;
q.pop();
while(q.top() + shift <= 0){
result += slope * (q.top() + shift - x);
x = q.top() + shift;
q.pop();
slope++;
}
result += slope *(0 - x);
}
cout<<result;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
1868 KB |
Output is correct |
5 |
Correct |
39 ms |
3284 KB |
Output is correct |
6 |
Correct |
114 ms |
6492 KB |
Output is correct |
7 |
Correct |
156 ms |
12472 KB |
Output is correct |
8 |
Execution timed out |
1095 ms |
12544 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
18 ms |
1868 KB |
Output is correct |
5 |
Correct |
39 ms |
3284 KB |
Output is correct |
6 |
Correct |
114 ms |
6492 KB |
Output is correct |
7 |
Correct |
156 ms |
12472 KB |
Output is correct |
8 |
Execution timed out |
1095 ms |
12544 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
460 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
18 ms |
1868 KB |
Output is correct |
12 |
Correct |
39 ms |
3284 KB |
Output is correct |
13 |
Correct |
114 ms |
6492 KB |
Output is correct |
14 |
Correct |
156 ms |
12472 KB |
Output is correct |
15 |
Execution timed out |
1095 ms |
12544 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |