-
Notifications
You must be signed in to change notification settings - Fork 0
/
INOI1201.cpp
228 lines (175 loc) · 4.48 KB
/
INOI1201.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
// Krishnaya vaasudevaya
// Devaki nandanayacha
// Nanda gopakumaraya
// Govindaya namoh namaha
// Jay ganeshji, Jay Guruji, Jay Ram-bhakt Hanumanji
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb emplace_back
#define eb emplace
// Competion only
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ull = unsigned ll;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
const int inf = 1e9 + 7;
const ll llinf = 1e18 + 7;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll fastPow(ll a, ll b)
{
ll res = 1;
while(b) {
if(b & 1)
res *= a;
a *= a, b >>= 1;
}
return res;
}
ll fastPow(ll a, ll b, ll m)
{
ll res = 1;
a %= m;
while(b) {
if(b & 1)
(res *= a) %= m;
(a *= a) %= m, b >>= 1;
}
return res;
}
ll modinv(ll x, ll m)
{
return fastPow(x, m - 2, m);
}
ll moddiv(ll numerator, ll denominator, ll m) {
return numerator * modinv(denominator, m);
}
template<typename T>
constexpr ostream &operator<<(ostream &stream, const vector<T> &other) {
stream << '[';
size_t n = other.size();
if(n > 0) {
for(size_t i = 0; i < n - 1; i++)
stream << other[i] << ", ";
stream << other[n - 1];
}
return stream << ']';
}
template<typename T>
constexpr ostream &operator<<(ostream &stream, const set<T> &other) {
stream << '{';
size_t n = other.size();
if(n > 0) {
auto it = other.begin();
for(size_t i = 0; i < n-1; i++)
stream << *it << ", ", ++it;
stream << *it;
}
return stream << '}';
}
template<typename T>
constexpr ostream &operator<<(ostream &stream, const multiset<T> &other) {
stream << '{';
size_t n = other.size();
if(n > 0) {
auto it = other.begin();
for(size_t i = 0; i < n-1; i++)
stream << *it << ", ", ++it;
stream << *it;
}
return stream << '}';
}
template<typename T>
constexpr ostream &operator<<(ostream &stream, const ordered_set<T> &other) {
stream << '{';
size_t n = other.size();
if(n > 0) {
auto it = other.begin();
for(size_t i = 0; i < n-1; i++)
stream << *it << ", ", ++it;
stream << *it;
}
return stream << '}';
}
template<typename T1, typename T2>
constexpr ostream &operator<<(ostream &stream, const map<T1, T2> &other) {
stream << '{';
size_t n = other.size();
if(n > 0) {
auto it = other.begin();
for(size_t i = 0; i < n-1; i++)
stream << (*it).first << ':' << (*it).second << ", ", ++it;
stream << (*it).first << ':' << (*it).second;
}
return stream << '}';
}
template<typename T1, typename T2>
constexpr ostream &operator<<(ostream &stream, const multimap<T1, T2> &other) {
stream << '{';
size_t n = other.size();
if(n > 0) {
auto it = other.begin();
for(size_t i = 0; i < n-1; i++)
stream << (*it).first << ':' << (*it).second << ", ", ++it;
stream << (*it).first << ':' << (*it).second;
}
return stream << '}';
}
template<typename T1, typename T2>
constexpr ostream &operator<<(ostream &stream, const unordered_map<T1, T2> &other) {
stream << '{';
size_t n = other.size();
if(n > 0) {
auto it = other.begin();
for(size_t i = 0; i < n-1; i++)
stream << (*it).first << ':' << (*it).second << ", ", ++it;
stream << (*it).first << ':' << (*it).second;
}
return stream << '}';
}
template<typename T1, typename T2>
constexpr ostream &operator<<(ostream &stream, const pair<T1, T2> &other) {
return stream << '(' << other.first << ", " << other.second << ')';
}
template<typename T>
istream &operator>>(istream &stream, vector<T> &other) {
for(auto &e : other)
stream >> e;
return stream;
}
template<typename T1, typename T2>
istream &operator>>(istream &stream, pair<T1, T2> &other) {
stream >> other.first >> other.second;
return stream;
}
inline void solve() {
}
int main(int argc, char *argv[]) {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, res = 0; cin >> n;
vii a(n);
for(int i = 0, c; i < n; i++)
cin >> a[i].ff >> a[i].ss >> c, a[i].ss += c;
sort(a.begin(), a.end(), [](pii &A, pii &B) {
int x = A.ff + max(A.ss, B.ff + B.ss), // time taken if a goes before b
y = B.ff + max(B.ss, A.ff + A.ss); // time taken if b goes before a
return x < y;
});
for(int i = 0, t = 0; i < n; i++)
t += a[i].ff, res = max(res, t + a[i].ss);
cout << res << '\n';
return 0;
}