#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ll n,q;
cin >> n >> q;
vector<pair<ll , ll>> v;
stack<ll> s;
ll p[n];
for (ll i=0; n>i; i++)
{
p[i] = 0;
}
ll sum[n];
for (ll i=0; n>i; i++)
{
ll a,b;
cin >> a >> b;
v.push_back({a , b});
sum[i] = v[i].second;
if (i > 0) sum[i] += sum[i-1];
}
while (q--)
{
ll a,b;
cin >> a >> b;
a--;
for (ll i=0; n>i; i++)
{
if (a == 0 && sum[i] >= b)
{
cout << i + 1 << endl;
a = -3;
break;
}
if (a > 0 && sum[i] - sum[a - 1] >= b)
{
cout << i + 1 << endl;
a = -3;
break;
}
}
if (a != -3)
{
cout << 0 << endl;
}
}
return 0;
}
Compilation message
fountain.cpp: In function 'int main()':
fountain.cpp:13:5: warning: variable 'p' set but not used [-Wunused-but-set-variable]
13 | ll p[n];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1589 ms |
3948 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |