# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1104977 |
2024-10-25T03:17:28 Z |
Faggi |
Sails (IOI07_sails) |
C++11 |
|
44 ms |
4936 KB |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll>tamDP;
vector<ll>calcs;
ll tam;
bool can(vector<ll> dp,ll x)
{
ll ma, sob, i;
for(i=tam; i>0; i--)
{
ma=min(x,tamDP[i]);
sob=0;
if(dp[i]>ma)
{
sob=dp[i]-ma;
dp[i]=ma;
if(i>1)
dp[i-1]+=sob;
else
return 0;
}
}
return 1;
}
ll calc(vector<ll> & dp, ll x)
{
ll ma, sob, i, res=0;
for(i=tam; i>0; i--)
{
ma=min(x,tamDP[i]);
sob=0;
if(dp[i]>ma)
{
sob=dp[i]-ma;
dp[i]=ma;
dp[i-1]+=sob;
}
}
for(i=tam; i>0; i--)
{
res+=calcs[dp[i]];
}
return res;
}
int main()
{
ll n, i, mi=0, ma=0, piv,pos;
cin >> n;
calcs.resize(n+1);
calcs[0]=0;
calcs[1]=0;
for(i=2; i<=n; i++)
{
calcs[i]+=calcs[i-1]+(i-1);
}
vector<pair<ll,ll>>v(n);
for(i=0; i<n; i++)
{
cin >> v[i].first >> v[i].second;
tam=max(v[i].first,tam);
}
vector<ll> dp(tam+1,0);
tamDP.resize(tam+1,0);
for(i=0; i<n; i++)
{
dp[v[i].first]+=1;
dp[v[i].first-v[i].second]-=1;
tamDP[v[i].first]+=1;
}
ma=dp[tam];
for(i=tam-1; i>=0; i--)
{
dp[i]+=dp[i+1];
ma=max(ma,dp[i]);
tamDP[i]+=tamDP[i+1];
}
pos=ma;
ma=LLONG_MAX;
while(mi<=ma)
{
piv=(mi+ma)/2;
if(can(dp,piv))
{
ma=piv-1;
pos=piv;
}
else
{
mi=piv+1;
}
}
cout << calc(dp,pos);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
1636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
23 ms |
2760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
36 ms |
4516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
4844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
4936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |