Submission #412436

# Submission time Handle Problem Language Result Execution time Memory
412436 2021-05-26T21:42:14 Z Dakto Sails (IOI07_sails) C++17
60 / 100
75 ms 3368 KB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> v(n);
    for(int i=0; i<n; i++) cin>>v[i].first>>v[i].second;
    long long res=1e16;
    long long s=0;
    for(auto i:v) s+=i.second;

    vector<long long> da(100000,0), cnt(100050,0), nv(100005,0);
    for(auto i:v){
        da[i.first]++;
        da[i.first-i.second]--;
        cnt[i.first]++;
    } 

    for(int i=100000; i>=1; i--){
        nv[i]=nv[i+1]+da[i];
        cnt[i]+=cnt[i+1];
    }

    auto check=[&](long long c){
        long long v=0;
        long long tr=0;
        long long ts=0;
        for(int i=100000; i>=1; i--){
            v+=nv[i];
            int d=min(min(v,cnt[i]),c-(s-ts-i*(c-1)<=0?1:0));
            tr+=d*(d-1)/2;
            ts+=d;
            v-=d;
        }
        if(!v) res=min(res,tr);
        return v==0;
    };
    int l=1, r=1e5;
    while(l<r){
        int m=(l+r)/2;
        if(check(m)) r=m;
        else l=m+1;
    }
    cout<<res<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2636 KB Output is correct
2 Correct 12 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2636 KB Output is correct
2 Correct 12 ms 2664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 2656 KB Output is correct
2 Correct 11 ms 2660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 2636 KB Output is correct
2 Correct 12 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 2636 KB Output is correct
2 Correct 12 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2708 KB Output is correct
2 Correct 28 ms 3136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 2756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 42 ms 2996 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 65 ms 3228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 68 ms 3308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 3368 KB Output isn't correct
2 Halted 0 ms 0 KB -