# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1018004 |
2024-07-09T12:32:56 Z |
ttamx |
Sails (IOI07_sails) |
C++17 |
|
1000 ms |
2256 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N=1e5+5;
int n;
vector<pair<int,int>> a;
deque<pair<int,int>> dq;
int pre;
ll ans;
int main(){
cin.tie(nullptr)->sync_with_stdio(false);
cin >> n;
a.resize(n);
for(auto &[h,k]:a)cin >> h >> k;
sort(a.rbegin(),a.rend());
dq.emplace_back(0,a[0].first);
pre=a[0].first;
for(auto [h,k]:a){
if(h<pre){
int dif=pre-h;
while(dif>0){
auto [val,cnt]=dq.front();
int used=min(dif,cnt);
dq.front().second-=used;
ans+=1LL*val*(val-1)/2*used;
if(dq.front().second==0)dq.pop_front();
dif-=used;
}
pre=h;
}
while(!dq.empty()&&k>=dq.back().second){
dq.back().first++;
auto [val,cnt]=dq.back();
k-=cnt;
if(dq.size()>1&&val==dq.end()[-2].first){
dq.pop_back();
dq.back().second+=cnt;
}
}
if(k>0){
auto [val,cnt]=dq.back();
dq.pop_back();
dq.emplace_back(val+1,k);
dq.emplace_back(val,cnt-k);
}
}
for(auto [val,cnt]:dq)ans+=1LL*val*(val-1)/2*cnt;
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
856 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
739 ms |
1372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1026 ms |
1884 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
2140 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1012 ms |
2256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |