Submission #576517

# Submission time Handle Problem Language Result Execution time Memory
576517 2022-06-13T07:09:59 Z Yazan_SA Fountain (eJOI20_fountain) C++14
30 / 100
85 ms 2724 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--)
    {
        ll 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=1; i<n; i++)
        {
            pref[i]=pref[i-1]+v[i].second;
            /*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;
                    iscnt[j]=1;
                }
            }*/
        }
        /*for(int i=0; i<n; cout<<pref[i++]<<' ');
        cout<<endl;*/
        while(q--)
        {
            cin>>r>>val;
            bool is=0;
            if(val>pref[n-1]-pref[r-2] && r>1)
                cout<<0;
            else if(val>pref[n-1] && r==1)
                cout<<0;
            else
            {
                if(r>1)
                    val+=pref[r-2];
                cout<<lower_bound(pref+r-1, pref+n, val)-pref+1;
            }
            cout<<endl;
        }
    }
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:47:18: warning: unused variable 'is' [-Wunused-variable]
   47 |             bool is=0;
      |                  ^~
fountain.cpp:16:18: warning: unused variable 'd' [-Wunused-variable]
   16 |         ll n, q, d, c, r, val;
      |                  ^
fountain.cpp:16:21: warning: unused variable 'c' [-Wunused-variable]
   16 |         ll n, q, d, c, r, val;
      |                     ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 71 ms 2724 KB Output is correct
2 Correct 85 ms 2708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -