This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |