답안 #173009

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
173009 2020-01-03T04:15:49 Z tourist 금 캐기 (IZhO14_divide) C++14
17 / 100
7 ms 888 KB
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define ll long long
#define sz(x) (int)x.size()
#define pii pair < int, int >
#define endl "\n"
#define METH ios::sync_with_stdio(0); cin.tie(0);
#define BEGIN cout << "BEGIN" << endl;
#define END cout << "END" << endl;

const int N = 1e5 + 9;
const int mod = 1e9 + 7;															/// ANOTHER HASH MOD: 228228227
const int prime = 29;																	/// ANOTHER HASH PRIME: 997
const int INF = ((long long) 0xCAFEBABE - 1e9 - 4e8);

int n, suf[N];
ll g[N], en[N];
vector < pii > eq;
vector < pair < int, pii > > v;

inline void read() {
	scanf("%d", &n);
	v.push_back({0, {0, 0}});
	for (int i = 1; i <= n; i++) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		v.push_back({a, {b, c}});
		en[i] = en[i - 1] + c;
		eq.push_back({en[i] - a, i});
		g[i] = g[i - 1] + b;
	}
}

ll calc(int id) {
	pii temp = {-(v[id].first - en[id - 1]), 0};
	int index = lower_bound(eq.begin(), eq.end(), temp) - eq.begin();
	return g[suf[index]] - g[id - 1];
}

inline void solve() {
	ll ans = 0;
	sort(eq.begin(), eq.end());

	for (int i = n - 1; i >= 0; i--) {
		suf[i] = max(suf[i + 1], eq[i].second);
	}

	for (int i = 1; i <= n; i++) {
		ans = max(ans, calc(i));
	}

	cout << ans << endl;
}

int main() {
	int t;
	t = 1;

	while (t--) {
		read();
		solve();
	}
}

Compilation message

divide.cpp: In function 'void read()':
divide.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
divide.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d", &a, &b, &c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 296 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 3 ms 376 KB Output is correct
6 Incorrect 3 ms 504 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 6 ms 888 KB Output is correct
3 Incorrect 7 ms 888 KB Output isn't correct
4 Halted 0 ms 0 KB -