이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fountain pair<int,int>
#define len first
#define vol second
void fastIO()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main()
{
fastIO();
int n, q, pos, lits;
cin >> n >> q;
vector <fountain> v(n);
vector <int> next(n, -1);
for (int i = 0; i < n; i++) cin >> v[i].len >> v[i].vol;
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
if (v[j].len > v[i].len)
{
next[i] = j;
break;
}
for (int i = 0; i < q; i++)
{
cin >> pos >> lits; pos--;
while (pos != -1)
{
lits -= v[pos].vol;
if (lits <= 0)
{
cout << pos + 1 << '\n';
break;
}
pos = next[pos];
}
if (lits > 0) cout << 0 << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |