-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD_This_Is_the_Last_Time.cpp
More file actions
54 lines (53 loc) · 1.57 KB
/
D_This_Is_the_Last_Time.cpp
File metadata and controls
54 lines (53 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const char nl = '\n';
// Author oGhostyyy
/* Thinking: n casinos */
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt; cin >> tt;
while(tt--){
int n; cin >> n; //casinos
ll k; cin >> k; //coins
vector<tuple<ll,ll,ll>> casinos(n); //data
for(int i = 0; i < n; i++){
ll l, r, real;
cin >> l;
cin >> r;
cin >> real;
casinos[i] = {l, r, real};
}
sort(casinos.begin(),casinos.end(),[](auto &l, auto &r){
return get<0>(l) < get<0>(r); //sort by starting requirement
});
priority_queue<pair<ll,ll>> pq;//get largest real
ll coins = k; //couns we have
int i = 0;
while (true) {
//add casinos l <= coins
while(i < n && get<0>(casinos[i]) <= coins){
pq.push({get<2>(casinos[i]), get<1>(casinos[i])});
i++;
}
bool played = false;
//pick heightest reali, top of pq
while(!pq.empty()) {
auto [realv, rv] = pq.top();
//cant enter/ no increase
if (rv < coins || realv <= coins) {
pq.pop();
continue;
}
// play and increase coins
coins = realv;
pq.pop();
played = true;
break;
}
if(!played) break;
}
cout << coins << nl;
}
}