Submission #840789

# Submission time Handle Problem Language Result Execution time Memory
840789 2023-08-31T17:05:55 Z Andrijanikolic73 Fountain (eJOI20_fountain) C++17
60 / 100
272 ms 6256 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n,q;
    cin>>n>>q;
    int koliko[n+1];
    int staje[n+1];
    for(int i=1;i<=n;i++)cin>>koliko[i]>>staje[i];
    if(n<=1000&&q<=2000){
            while(q--){
            int r,k;
            cin>>r>>k;
            vector<int>R;
            int z=r;
            R.push_back(r);
            for(int i=z;i<n;i=z){
                //cout<<i<<" ";
                int ok=0;
                for(int j=i+1;j<=n;j++){
                    if(koliko[i]<koliko[j]){
                        ok=1;
                        z=j;
                        R.push_back(j);
                        break;
                    }
                }
                if(!ok)break;
            }
            int ans=0;
            for(auto it:R){
                k-=staje[it];
                if(k<=0){
                    ans=it;
                    break;
                }
            }
            cout<<ans;
            cout<<endl;
        }
        return 0;
    }
    int ok=1;
    for(int i=1;i<n;i++){
        ok&=(koliko[i]<koliko[i+1]);
    }
    if(ok){
        int pref[n+1];
        pref[0]=0;
        for(int i=1;i<=n;i++)pref[i]=pref[i-1]+staje[i];
        while(q--){
            int i,x;
            cin>>i>>x;
            int l=i,r=n,p=0;
            while(l<=r){
                int mid=(l+r)/2;
                if(pref[mid]-pref[i-1]>=x){
                    r=mid-1;
                    p=mid;
                }
                else l=mid+1;
            }
            cout<<p;
            cout<<endl;
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 7 ms 212 KB Output is correct
7 Correct 6 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 265 ms 4756 KB Output is correct
2 Correct 272 ms 6256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 212 KB Output is correct
3 Correct 3 ms 212 KB Output is correct
4 Correct 4 ms 212 KB Output is correct
5 Correct 7 ms 212 KB Output is correct
6 Correct 7 ms 212 KB Output is correct
7 Correct 6 ms 212 KB Output is correct
8 Correct 265 ms 4756 KB Output is correct
9 Correct 272 ms 6256 KB Output is correct
10 Incorrect 1 ms 212 KB Output isn't correct
11 Halted 0 ms 0 KB -