#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 |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
3520 KB |
Output is correct |
2 |
Correct |
255 ms |
3320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |