This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll n,q;
cin >> n >> q;
vector<pair<ll , ll>> v;
stack<ll> s;
ll sum[n];
for (ll i=0; n>i; i++)
{
ll a,b;
cin >> a >> b;
v.push_back({a , b});
sum[i] = v[i].second;
if (i > 0) sum[i] += sum[i-1];
}
while (q--)
{
ll a,b;
cin >> a >> b;
a--;
int g = b;
if (a > 0)
{
g += sum[a-1];
}
int l = 0 , mid = (n / 2) , r = n;
while (l != r)
{
if (sum[mid] >= g)
{
r = mid;
mid = (r + l) / 2;
}
else
{
l = mid + 1;
mid = (l + r) / 2;
}
}
if (r == n)
{
cout << 0 << endl;
}
else
{
cout << l + 1 << endl;
}
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |