답안 #1002652

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002652 2024-06-19T17:37:11 Z Lalic Autobahn (COI21_autobahn) C++17
100 / 100
76 ms 14792 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef complex<double> cd;

const int MAXN = 1e5+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1);

struct occ{
	ll x;
	int tipo, val;
	
	occ(ll a, int b, int c): x(a), tipo(b), val(c) {}
	
	bool operator < (occ a) const{
		return this->x < a.x;
	}
};

void solve(){
	int n, k, x; cin >> n >> k >> x;
	vector<occ> arr;
	
	for(int i=0;i<n;i++){
		ll l, t, r; cin >> l >> t >> r;
		
		arr.pb(occ(l, 0, 1));
		arr.pb(occ(r+1, 0, -1));
		if(l+t<=r){
			arr.pb(occ(l+t, 1, 1));
			arr.pb(occ(r+1, 1, -1));
		}
	}
	
	sort(all(arr));
	arr.pb(occ(LINF, 0, 0));
	
	int low=-x, high=0, ptrl=0, ptrh=0;
	ll normH=0, normL=0, specH=0, specL=0, curr=0, ans=0;
	while(1){
		if(ptrh==(int)arr.size()-1 && ptrl==(int)arr.size()-1) break;
		
		if(arr[ptrh].x-high<=arr[ptrl].x-low){
			ll diff=arr[ptrh].x-high;
			if(normH>=k) curr+=specH*diff;
			if(normL>=k) curr-=specL*diff;
			
			if(arr[ptrh].tipo==0) normH+=arr[ptrh].val;
			else specH+=arr[ptrh].val;
			
			high+=diff;
			low+=diff;
			ptrh++;
		}
		else{
			ll diff=arr[ptrl].x-low;
			if(normH>=k) curr+=specH*diff;
			if(normL>=k) curr-=specL*diff;
			
			if(arr[ptrl].tipo==0) normL+=arr[ptrl].val;
			else specL+=arr[ptrl].val;
			
			high+=diff;
			low+=diff;
			ptrl++;
		}
		
		while(arr[ptrh].x-high==0){
			if(arr[ptrh].tipo==0) normH+=arr[ptrh].val;
			else specH+=arr[ptrh].val;
			ptrh++;
		}
		
		while(arr[ptrl].x-low==0){
			if(arr[ptrl].tipo==0) normL+=arr[ptrl].val;
			else specL+=arr[ptrl].val;
			ptrl++;
		}
		
		ans=max(ans, curr);
	}
	
	cout << ans << "\n";
}
	

int32_t main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	
	int tt=1;
	//~ cin >> tt;
	while(tt--) solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 61 ms 12800 KB Output is correct
22 Correct 61 ms 12724 KB Output is correct
23 Correct 60 ms 12728 KB Output is correct
24 Correct 64 ms 12744 KB Output is correct
25 Correct 76 ms 14780 KB Output is correct
26 Correct 58 ms 14780 KB Output is correct
27 Correct 59 ms 14764 KB Output is correct
28 Correct 60 ms 14784 KB Output is correct
29 Correct 59 ms 14792 KB Output is correct