#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MAX 5e4 + 1
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 0x3F3F3F3F3F3F3F3FLL
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sec second
#define fi first
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
int main()
{
OPT
int n, q;
cin >> n >> q;
vector<int> c(n+1), d(n+1);
for(int i = 1; i<=n; i++)
{
cin >> d[i] >> c[i];
}
while(q--)
{
int r, v, ans = 0;
cin >> r >> v;
int temp = d[r];
v-=c[r];
ans = r;
if(v > 0)
{
for(int i = r+1; i<=n; i++)
{
if(d[i] > temp && v>0)
{
temp = d[i];
v -= c[i];
ans = i;
}
}
}
if(v>0)ans = 0;
cerr << "ans : ";
cout << ans << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
340 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
11 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1533 ms |
1400 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
212 KB |
Output is correct |
4 |
Correct |
6 ms |
340 KB |
Output is correct |
5 |
Correct |
7 ms |
340 KB |
Output is correct |
6 |
Correct |
11 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
340 KB |
Output is correct |
8 |
Execution timed out |
1533 ms |
1400 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |