Submission #576431

# Submission time Handle Problem Language Result Execution time Memory
576431 2022-06-13T05:59:35 Z Yazan_SA Fountain (eJOI20_fountain) C++14
0 / 100
1500 ms 1712 KB
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define start cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
using namespace std;

bool iscnt[100000];
int main()
{
    start
    //freopen("survive.in", "r", stdin);
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n, q, d, c, r, val;
        vector<pair<int,int>>v;
        ll pref[100000];
        cin>>n>>q;
        for(int i=0; i<n; i++)
        {
            int x, y;
            cin>>x>>y;
            v.push_back({x, y});
        }
        pref[0]=v[0].second;
        for(int i=0; i<n; i++)
        {
            if(iscnt[i]==0)
            {
                iscnt[i]=1;
                pref[i]=v[i].second;
                for(int j=i+1; j<n; j++)
                {
                    if(v[j]<=v[i])
                        break;
                    pref[j]=pref[j-1]+v[j].second;
                    iscnt[j]=1;
                }
            }
        }
        while(q--)
        {
            cin>>r>>val;
            bool is=0;
            int prev=r-1;
            for(int i=r-1; i<n; i++)
            {
                if(v[prev].first>v[i].first && i!=r-1)
                    continue;
                prev=i;
                val-=v[i].second;
                if(val<=0)
                {
                    is=1;
                    break;
                }
            }
            cout<<(is ? prev+1 : 0)<<endl;
        }
    }
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:16:19: warning: unused variable 'd' [-Wunused-variable]
   16 |         int n, q, d, c, r, val;
      |                   ^
fountain.cpp:16:22: warning: unused variable 'c' [-Wunused-variable]
   16 |         int n, q, d, c, r, val;
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1570 ms 1712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -