# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54385 |
2018-07-03T09:41:12 Z |
노영훈(#1472) |
Sails (IOI07_sails) |
C++11 |
|
41 ms |
3772 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=100010, inf=2e9, HMX=100000;
const ll linf=2e17;
int n;
pii P[MX];
ll tree[MX];
void upt(int pos, int val){
for(; pos>0; pos-=pos&(-pos))
tree[pos]+=val;
}
void upt(int l, int r, int val){
if(r<l) return;
// cout<<l<<' '<<r<<'\n';
upt(r, val); upt(l-1, -val);
}
int val(int pos){
ll res=0;
for(; 0<pos && pos<=HMX; pos+=pos&(-pos))
res+=tree[pos];
return res;
}
ll cnt[MX];
ll solve(int x){
ll A[MX];
for(int i=1; i<=HMX; i++) A[i]=cnt[i];
ll rem=0;
for(int i=HMX; i>=1; i--){
if(A[i]>=x){
ll k=A[i]-x;
A[i]-=k, rem+=k;
}
else{
ll k=min(rem, 0LL+x-A[i]);
A[i]+=k; rem-=k;
}
}
if(rem>0) return linf;
ll ans=0;
for(int i=1; i<=HMX; i++)
ans+=A[i]*(A[i]-1)/2;
return ans;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0);
cin>>n;
for(int i=1; i<=n; i++){
int h, a; cin>>h>>a;
P[i]={h,a};
}
sort(P+1, P+n+1, greater<pii>());
for(int i=1; i<=n; i++){
int h,a; tie(h,a)=P[i];
int lo=h-a+1;
upt(lo, h, 1);
}
for(int i=1; i<=HMX; i++) cnt[i]=val(i);
ll S[MX]={};
for(int i=1; i<=n; i++) S[i]=S[i-1]+cnt[i];
ll rem=0;
for(int i=n; i>=1; i--){
if(cnt[i]<cnt[i-1]) continue;
ll now=(S[i]+rem+i-1)/i;
rem+=cnt[i]-now;
cnt[i]=now;
}
ll ans=0;
for(int i=1; i<=n; i++)
ans+=cnt[i]*(cnt[i]-1)/2;
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1912 KB |
Output is correct |
2 |
Incorrect |
5 ms |
1912 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
1944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
10 ms |
2340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
2596 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
2912 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
3616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
3680 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
3772 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |