#include <iostream>
using namespace std;
int N, Q, k, y = 0, n, v, vid, r;
int m[200005], i[100005], t[100005];
void F(int x)
{
if(i[y] < i[x])
{
m[y] = x;
return;
}
if(m[y] > 0 || m[x] <= 0)
{
if(x == N)
{
m[y] = -1;
}
return;
}
F(m[x]);
}
void F1(int w)
{
if(t[w] >= v)
{
v = 0;
n = w;
return;
}
if(v > t[w] && m[w] == -1)
{
n = -1;
return;
}
v -= t[w];
F1(m[w]);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> N >> Q;
r = (1 + N) / 2;
int g;
for(int a = 1; a <= N; a++)
{
cin >> i[a] >> t[a];
}
m[N] = -1;
for(int a = N; a >= 1; a--)
{
if(i[a] < i[a + 1])
{
m[a] = a + 1;
}
else
{
y = a;
F(a + 1);
if(m[a] == 0)
{
m[a] = N - 1;
}
}
}
for(int a = 0; a < Q; a++)
{
cin >> n >> v;
n;
F1(n);
if(v < 0)
{
cout << 0 << '\n';
}
else
{
cout << max(n, 0) << '\n';
}
}
return 0;
}
Compilation message
fountain.cpp: In function 'int main()':
fountain.cpp:75:9: warning: statement has no effect [-Wunused-value]
75 | n;
| ^
fountain.cpp:50:9: warning: unused variable 'g' [-Wunused-variable]
50 | int g;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1540 ms |
1876 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
1540 ms |
1876 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |