답안 #455296

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
455296 2021-08-05T19:16:34 Z armand Fountain (eJOI20_fountain) C++14
60 / 100
1500 ms 2532 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 3 ms 204 KB Output is correct
4 Correct 4 ms 204 KB Output is correct
5 Correct 6 ms 204 KB Output is correct
6 Correct 6 ms 204 KB Output is correct
7 Correct 5 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 371 ms 2532 KB Output is correct
2 Correct 418 ms 2400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 204 KB Output is correct
3 Correct 3 ms 204 KB Output is correct
4 Correct 4 ms 204 KB Output is correct
5 Correct 6 ms 204 KB Output is correct
6 Correct 6 ms 204 KB Output is correct
7 Correct 5 ms 204 KB Output is correct
8 Correct 371 ms 2532 KB Output is correct
9 Correct 418 ms 2400 KB Output is correct
10 Correct 7 ms 204 KB Output is correct
11 Execution timed out 1571 ms 1360 KB Time limit exceeded
12 Halted 0 ms 0 KB -