# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
74725 | goodbaton | Sails (IOI07_sails) | C++14 | 42 ms | 8448 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef long long ll;
#define SIZE 100010
int main(){
int n,h,k,max_h=0;
ll sum[SIZE] = {};
priority_queue<pair<ll,ll> > pq;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d%d",&h,&k);
max_h = max(max_h,h);
sum[h]++;
sum[h-k]--;
}
for(int i=max_h;i>0;i--){
sum[i-1] += sum[i];
}
for(int i=1;i<=max_h;i++){
ll v = 1;
sum[i] *= -1;
while(pq.size() && pq.top().first > sum[i]/v){
pair<ll,ll> p = pq.top();
pq.pop();
sum[i] += p.first * p.second;
v += p.second;
}
sum[i] *= -1;
if(sum[i]%v==0){
pq.push(make_pair(-(sum[i]/v),v));
}else{
pq.push(make_pair(-(sum[i]/v+1),sum[i]%v));
pq.push(make_pair(-(sum[i]/v),v-sum[i]%v));
}
}
ll ans = 0;
while(pq.size()){
pair<ll,ll> p = pq.top();
pq.pop();
p.first *= -1;
ans += p.first*(p.first-1)/2 * p.second;
}
printf("%lld\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |