답안 #21835

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
21835 2017-04-26T09:14:38 Z ulna 금 캐기 (IZhO14_divide) C++11
100 / 100
96 ms 10572 KB
#include <bits/stdc++.h>
using namespace std;

// why am I so weak

int n;
long long x[100055], g[100055], d[100055];

typedef pair<long long, int> P;

#define ft first
#define sd second

int main() {
	// sigma(ei ... ej) >= x[j] - x[i]
	// e[j] - e[i - 1] >= x[j] - x[i]
	// x[i] - e[i - 1] >= x[j] - e[j]
	
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		scanf("%lld %lld %lld", &x[i], &g[i], &d[i]);

		if (i) {
			g[i] += g[i - 1];
			d[i] += d[i - 1];
		}
	}

	set<P> s;
	long long res = g[0];

	s.insert(P(x[0], 0));

	for (int i = 0; i < n; i++) {
		res = max(res, g[i] - g[i - 1]);

		{
			auto ite = s.lower_bound(P(x[i] - d[i], -1));

			if (ite != s.end()) {
				res = max(res, g[i] - (ite->sd == 0 ? 0ll : g[ite->sd - 1]));
			}
		}

		if (x[i] - d[i - 1] > s.rbegin()->ft) {
			s.insert(P(x[i] - d[i - 1], i));
		}
	}

	printf("%lld\n", res);
	
	return 0;
}

Compilation message

divide.cpp: In function 'int main()':
divide.cpp:19:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
divide.cpp:22:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld", &x[i], &g[i], &d[i]);
                                               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4368 KB Output is correct
2 Correct 0 ms 4368 KB Output is correct
3 Correct 0 ms 4368 KB Output is correct
4 Correct 0 ms 4368 KB Output is correct
5 Correct 0 ms 4368 KB Output is correct
6 Correct 0 ms 4368 KB Output is correct
7 Correct 0 ms 4368 KB Output is correct
8 Correct 0 ms 4368 KB Output is correct
9 Correct 0 ms 4368 KB Output is correct
10 Correct 0 ms 4368 KB Output is correct
11 Correct 0 ms 4368 KB Output is correct
12 Correct 0 ms 4368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4368 KB Output is correct
2 Correct 0 ms 4368 KB Output is correct
3 Correct 0 ms 4368 KB Output is correct
4 Correct 0 ms 4368 KB Output is correct
5 Correct 0 ms 4368 KB Output is correct
6 Correct 0 ms 4368 KB Output is correct
7 Correct 0 ms 4368 KB Output is correct
8 Correct 0 ms 4368 KB Output is correct
9 Correct 0 ms 4368 KB Output is correct
10 Correct 0 ms 4500 KB Output is correct
11 Correct 3 ms 4632 KB Output is correct
12 Correct 0 ms 4632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4368 KB Output is correct
2 Correct 3 ms 4368 KB Output is correct
3 Correct 3 ms 4368 KB Output is correct
4 Correct 19 ms 4368 KB Output is correct
5 Correct 19 ms 4368 KB Output is correct
6 Correct 46 ms 4368 KB Output is correct
7 Correct 56 ms 4368 KB Output is correct
8 Correct 49 ms 4368 KB Output is correct
9 Correct 43 ms 4368 KB Output is correct
10 Correct 63 ms 7536 KB Output is correct
11 Correct 96 ms 10572 KB Output is correct
12 Correct 93 ms 10308 KB Output is correct