답안 #340747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340747 2020-12-28T10:29:27 Z tengiz05 금 캐기 (IZhO14_divide) C++17
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
template<class T> bool chmin(T& a, const T& b) {return a>b? a=b, true:false;}
template<class T> bool chmax(T& a, const T& b) {return a<b? a=b, true:false;}
const int mod = 1e9+7, N = 2e5+5;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val)-1;}
int a[N], n, m, k;
int prd[N];
int prg[N];
int mx[N*4];
void update(int pos, int L, int R, int x, int val){
	if(L == R){
		mx[x] = val;
		return;
	}int mid = (L+R)/2;
	if(mid >= pos)update(pos, L, mid, x*2, val);
	else update(pos, mid+1, R, x*2+1, val);
	mx[x] = max(mx[x*2], mx[x*2+1]);
}
int tmp;
int get(int l, int r, int L, int R, int x){
	if(L > r || R < l)return 0;
	if(L == R)return L;
	int mid = (L+R)/2;
	if(L >= l && R <= r){
		if(mx[x*2+1] >= tmp)return get(l, r, mid+1, R, x*2+1);
		else return get(l, r, L, mid, x*2);
	}return max(get(l, r, L, mid, x*2), get(l, r, mid+1, R, x*2+1));
}
void solve(int test_case){
	int i, j;
	vector<tuple<int, int, int>> v;
	cin >> n;
	v.pb(make_tuple(0,0,0));
	for(i=0;i<n;i++){
		int x, g, d;
		cin >> x >> g >> d;
		v.pb(make_tuple(x, g, d));
	}
	sort(all(v));
	for(i=1;i<=n;i++){
		prd[i] = prd[i-1] + get<2>(v[i]);
		prg[i] = prg[i-1] + get<1>(v[i]);
		update(i, 1, n, 1, prd[i] - get<0>(v[i]));
	}
	int ans = 0;
	for(i=0;i<n;i++){
		tmp = prd[i] - get<0>(v[i]);
		int t = get(i+1, n, 1, n, 1);
		chmax(ans, prg[t] - prg[i]);
	}
	cout << ans << '\n';
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int _T;
	cin >> _T;
	for(int T_CASE = 1; T_CASE <= _T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




Compilation message

divide.cpp: In function 'void solve(long long int)':
divide.cpp:40:9: warning: unused variable 'j' [-Wunused-variable]
   40 |  int i, j;
      |         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -