#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[i].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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1578 ms |
3352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
452 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |