#include <bits/stdc++.h>
using namespace std;
#define MAXN 100010
vector<long long> adj[MAXN];
bool pos[MAXN];
long long d[MAXN],c[MAXN];
long long n,q;
long long br;
void dfs(long long node,long long vv)
{
pos[node]=true;
vv=-c[node];
if (vv<=0)
{
br=node;
return;
}
long long s=adj[node].size();
for (long long i=0;i<s;i++)
{
long long sled=adj[node][i];
if (pos[sled]==false) dfs(sled,vv);
}
}
int main()
{
cin>>n>>q;
for (long long i=1;i<=n;i++) cin>>d[i]>>c[i];
for (long long i=1;i<n;i++) adj[i].push_back(i+1);
for (long long i=1;i<=q;i++)
{
long long r,v;
cin>>r>>v;
br=0;
dfs(r,v);
cout<<br<<endl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
273 ms |
10640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |