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>
using namespace std;
int vkupno[100005];
int n, q;
int binarno(int rezervoar, int voda) {
int l=rezervoar-1, r=n+1;
while (l+1<r) {
int mid=(l+r)/2;
if (vkupno[mid]-vkupno[rezervoar-1]>=voda) r=mid;
else l=mid;
}
return r;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
int dijametar[n+1], kapacitet[n+1];
for (int i=1;i<=n;i++)
cin >> dijametar[i] >> kapacitet[i];
vkupno[0]=0;
for (int i=1;i<=n;i++)
vkupno[i]=vkupno[i-1]+kapacitet[i];
vkupno[n+1]=INT_MAX;
while (q--) {
int r, v;
cin >> r >> v;
int rez=binarno(r, v);
if (rez==n+1) cout << 0 << '\n';
else cout << rez << '\n';
}
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... |