Submission #878834

# Submission time Handle Problem Language Result Execution time Memory
878834 2023-11-25T10:05:58 Z christosalexand Fountain (eJOI20_fountain) C++14
0 / 100
238 ms 3228 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n,q;
    cin>>n>>q;
    int d[n], c[n];
    for (int i = 0; i<n; i++)
    {
        cin>>d[i]>>c[i];
    }
    while (q--)
    {
        int start, litres;
        cin>>start>>litres;
        int current = d[start-1];
        litres-=c[start-1];
        if (litres<=0)
        {
            cout<<start<<endl;
            continue;
        }
        bool b = false;
        int l = start-1;
        int r = n;
        int mid;
        int ans;
        while(l<r)
        {
            mid = (l+r)/2;
            if (d[mid]>current)
            {
                ans = mid;
                r = mid-1;
            }
            else
            {
                l++;
            }
        }
        litres-=c[mid];
        if (litres<=0)
        {
            cout<<mid<<endl;
            b = true;
        }
        
        if (!b)
        {
            cout<<0<<endl;
        }
    }

    return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:29:13: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
   29 |         int ans;
      |             ^~~
fountain.cpp:46:19: warning: 'mid' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |             cout<<mid<<endl;
      |                   ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 238 ms 3228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -