#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <iomanip>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector<pair<int, int>> reservoir;
int n,q;
int recur(int node,int quantity)
{
bool found = false;
if (quantity <= reservoir[node].second)
{
return node + 1;
}
int i = 0;
for (i = node + 1;i < n;i++)
{
if (reservoir[i].first > reservoir[node].first)
{
found = true;
break;
}
}
if (!found)
return 0;
return recur(i,quantity - reservoir[node].second);
}
int main() {
fast
cin >> n >> q;
for (int i = 0;i < n;i++)
{
int d,c;
cin >> d >> c;
reservoir.push_back({d,c});
}
for (int i = 0;i < q;i++)
{
int r,v;
cin >> r >> v;
cout << recur(r - 1,v) << endl;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1561 ms |
1500 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
4 ms |
508 KB |
Output is correct |
6 |
Correct |
3 ms |
348 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
8 |
Execution timed out |
1561 ms |
1500 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |