#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n; cin >> n;
vector<pair<int,int>> v(n);
for(auto &x : v)cin >> x.first >> x.second;
set<pair<int,int>> S;
S.insert({1,1});
S.insert({1,2});
int cn = 3;
sort(v.begin(),v.end());
for(int i = 0; i < n; ++i){
int mx = (*S.rbegin()).first;
int am = min(v[i].first+1,mx+v[i].second)-mx;
if(v[i].second == am){
S.erase(prev(S.end()));
S.insert({mx+am,cn++});
continue;
}
S.insert({mx+am,cn++});
auto it = S.lower_bound({v[i].first-v[i].second+1,0});
auto it2 = prev(it);
S.insert({(*it2).first+v[i].second-(v[i].first-(*it).first+1),cn++});
S.erase(it);
S.erase(it2);
S.insert({1,cn++});
}
vector<int> v2;
for(auto x : S)v2.push_back(x.first);
reverse(v2.begin(),v2.end());
long long ans = 0;
for(int i = 0; i < v2.size(); ++i){
ans += 1ll * i * (v2[i]-1);
}
cout << ans << '\n';
}
Compilation message
sails.cpp: In function 'int main()':
sails.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int i = 0; i < v2.size(); ++i){
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Runtime error |
1 ms |
452 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
460 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
828 KB |
Output is correct |
2 |
Runtime error |
9 ms |
1232 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
20 ms |
2528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
15 ms |
1760 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
19 ms |
2528 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
23 ms |
2888 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
34 ms |
3128 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |