# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
54396 |
2018-07-03T10:06:44 Z |
노영훈(#1472) |
Sails (IOI07_sails) |
C++11 |
|
29 ms |
2924 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 mx[MX];
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};
}
ll sum=0;
for(int i=1; i<=n; i++)
upt(1, P[i].first, 1), sum+=P[i].second;
for(int i=1; i<=HMX; i++) mx[i]=val(i);
for(int i=1; i<=HMX; i++) tree[i]=0;
for(int i=HMX; i>=1; i--){
if(mx[i]==0) continue;
ll x=min(sum/i, mx[i]);
upt(1,i,x);
sum-=x*i;
if(sum<=i && mx[i]>0){
upt(1, sum, 1);
break;
}
}
ll ans=0;
for(int i=1; i<=n; i++){
ll x=val(i);
ans+=x*(x-1)/2;
}
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1912 KB |
Output is correct |
2 |
Correct |
5 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1928 KB |
Output is correct |
2 |
Incorrect |
5 ms |
2056 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2056 KB |
Output is correct |
2 |
Correct |
5 ms |
2056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2056 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
2088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
2364 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
2512 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
21 ms |
2720 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
2796 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
2924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |