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;
#define fountain pair<int,int>
#define len first
#define vol second
void fastIO()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main()
{
fastIO();
int n, q, pos, lits;
cin >> n >> q;
vector <fountain> v(n);
vector <int> next(n, -1);
for (int i = 0; i < n; i++) cin >> v[i].len >> v[i].vol;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (v[j].len > v[i].len)
{
next[i] = j;
break;
}
for (int i = 0; i < q; i++)
{
cin >> pos >> lits; pos--;
while (pos != -1)
{
lits -= v[pos].vol;
if (lits <= 0)
{
cout << pos + 1 << '\n';
break;
}
pos = next[pos];
}
if (lits > 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... |