이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 100005;
int d[N], c[N];
int n, q;
long long pref[N];
bool is_increasing()
{
int i;
for (i = 2; i <= n; i++)
if (d[i] <= d[i - 1])
return false;
return true;
}
void solve2()
{
int i;
int r, w;
pref[1] = c[1];
for (i = 2; i <= n; i++)
pref[i] = pref[i - 1] + c[i];
while (q--) {
cin >> r >> w;
long long* pt = lower_bound(pref, pref + n + 1, w + pref[r - 1]);
int res = pt - pref;
if (res <= n)
cout << res << endl;
else
cout << 0 << endl;
}
}
int main()
{
int i;
int r, v;
cin >> n >> q;
for (i = 1; i <= n; i++)
cin >> d[i] >> c[i];
if (is_increasing()) {
solve2();
// system("pause");
return 0;
}
while (q--) {
cin >> r >> v;
if (v <= c[r]) {
cout << r << endl;
continue;
}
i = r + 1;
v -= c[r];
while (i <= n) {
if (d[i] > d[r]) {
if (v <= c[i]) {
cout << i << endl;
break;
}
else {
v -= c[i];
r = i;
i++;
}
}
else
i++;
}
if (i > n)
cout << 0 << endl;
}
// system("pause");
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |