Submission #1104974

# Submission time Handle Problem Language Result Execution time Memory
1104974 2024-10-25T03:15:16 Z Faggi Sails (IOI07_sails) C++11
25 / 100
40 ms 3912 KB
#include <bits/stdc++.h>

using namespace std;
vector<int>tamDP;
vector<int>calcs;
int tam;
bool can(vector<int> dp,int x)
{
    int 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;
}
int calc(vector<int> & dp, int x)
{
    int 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()
{
    int 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<int,int>>v(n);
    for(i=0; i<n; i++)
    {
        cin >> v[i].first >> v[i].second;
        tam=max(v[i].first,tam);
    }
    vector<int> 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;
    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 336 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 5 ms 848 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 1360 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 2120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 3272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 3648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 40 ms 3912 KB Output isn't correct
2 Halted 0 ms 0 KB -