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 main()
{
int n, q, x, y;
cin >> n >> q;
vector < vector <int> > cnt;
vector < pair <int, int> > v;
for (int i = 0; i < n; i++)
{
cin >> x >> y;
v.push_back({ x, y });
}
for (int i = 0; i < n; i++)
{
int prev = i;
cnt.push_back(vector <int>());
cnt[i].push_back(i);
for (int j = i; j < n; j++)
if (v[prev].first < v[j].first)
{
cnt[i].push_back(j);
prev = j;
}
}
for (int i = 0; i < q; i++)
{
cin >> x >> y;
for (int i = 0; i < n; i++)
{
if (i > 0 and cnt[x - 1][i] == 0) break;
y -= v[cnt[x - 1][i]].second;
if (y <= 0)
{
cout << cnt[x - 1][i] + 1 << '\n';
break;
}
}
if (y > 0) cout << 0 << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |