Submission #851566

# Submission time Handle Problem Language Result Execution time Memory
851566 2023-09-20T06:56:55 Z abcvuitunggio Sails (IOI07_sails) C++17
45 / 100
16 ms 1244 KB
#include <bits/stdc++.h>
using namespace std;
int n,h,k,sum,cnt[100002],a[100001];
long long res;
int main(){
    ios_base::sync_with_stdio(NULL);cin.tie(nullptr);
    cin >> n;
    cnt[1]=n;
    while (n--){
        cin >> h >> k;
        cnt[h+1]--;
        sum+=k;
    }
    for (int i=1;i<=100001;i++){
        cnt[i]+=cnt[i-1];
        if (!a[cnt[i]])
            a[cnt[i]]=i;
    }
    for (int i=1;i<=100000;i++)
        if (!a[i])
            a[i]=a[i-1];
    for (int i=100000;i>=1;i--)
        cnt[i]+=cnt[i+1];
    for (int i=1;i<=100000;i++){
        int l=0,r=100000,kq=-1;
        while (l<=r){
            int mid=(l+r)>>1;
            if (cnt[max(a[mid],i)]+mid*max(a[mid]-i,0)>=sum){
                kq=mid;
                r=mid-1;
            }
            else
                l=mid+1;
        }
        sum-=kq;
        res+=1LL*kq*(kq-1)/2;
    }
    cout << res;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1116 KB Output is correct
2 Correct 5 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1116 KB Output is correct
2 Correct 4 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1116 KB Output is correct
2 Correct 4 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1116 KB Output is correct
2 Correct 5 ms 1240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 1112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1024 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 1076 KB Output isn't correct
2 Halted 0 ms 0 KB -