Submission #1024728

# Submission time Handle Problem Language Result Execution time Memory
1024728 2024-07-16T09:45:28 Z angels Fountain (eJOI20_fountain) C++14
60 / 100
1500 ms 4948 KB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin>>n>>q;
    long long int d[n], c[n], prefix_sum[n+2];
    bool subtask1=0;
    prefix_sum[n+1]=INT_MAX;
    prefix_sum[0]=0;
    for(int i=0; i<n; i++)
    {
        cin>>d[i]>>c[i];
        if(i>1 && d[i-1]>=d[i])
        {
            subtask1=1;
        }
        prefix_sum[i+1]=c[i];
        if(i>=1)
        {
            prefix_sum[i+1]+=prefix_sum[i];
        }
    }
    if(subtask1 || (n<=1000 && q<=2000))
    {
        while(q--)
        {
            long long int nivo, voda;
            cin>>nivo>>voda;
            long long int curr=nivo, prev=d[nivo-1];
            voda-=c[nivo-1];
            bool kiki=0;
            for(int i=nivo; i<n; i++)
            {
                if(d[i]>prev && voda>0)
                {
                    prev=d[i];
                    voda-=c[i];
                    curr=i+1;
                }
                if(voda<=0)
                {
                    kiki=1;
                }
            }
            if(kiki)
                cout<<curr<<"\n";
            else
                cout<<0<<"\n";
        }
    }
    else                            //subtask2
    {
        while(q--)
        {
            long long int nivo, voda, rez=nivo;
            cin>>nivo>>voda;
            int l=nivo-1, r=n+1;
            while(r-l>1)
            {
                int mid=(l+r)/2;
                long long int aa=0;
                if(prefix_sum[mid]-prefix_sum[nivo-1]>=voda)
                {
                    r=mid;
                }
                else
                {
                    l=mid;
                }
            }
            rez=r;
            if(rez==n+1)
                cout<<"0\n";
            else
                cout<<rez<<"\n";
            cout.flush();
        }
    }
    

    return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:65:31: warning: unused variable 'aa' [-Wunused-variable]
   65 |                 long long int aa=0;
      |                               ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 173 ms 4176 KB Output is correct
2 Correct 199 ms 4948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 468 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 500 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 173 ms 4176 KB Output is correct
9 Correct 199 ms 4948 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Execution timed out 1560 ms 2564 KB Time limit exceeded
12 Halted 0 ms 0 KB -