Submission #1018009

# Submission time Handle Problem Language Result Execution time Memory
1018009 2024-07-09T12:36:50 Z ttamx Sails (IOI07_sails) C++17
5 / 100
20 ms 1116 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();
            if(!dq.empty()&&val+1==dq.back().first)dq.back().second+=k;
            else 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 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 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 0 ms 348 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 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 856 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -