File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+
3
+ using namespace std ;
4
+ using ll = int64_t ;
5
+ using ff = long double ;
6
+
7
+ int N;
8
+ vector<ll> H, S;
9
+
10
+ ll solve () {
11
+ const ll inf = numeric_limits<ll>::max ();
12
+ ll ans = 0 ;
13
+ // O(N**2)
14
+ vector<bool > done (N, false );
15
+ for (int t = N - 1 ; t >= 0 ; --t) {
16
+ int min_index;
17
+ ll min_height = inf;
18
+ for (int i = 0 ; i < N; ++i) {
19
+ if (done[i]) continue ;
20
+ ll height = H[i] + t * S[i];
21
+ bool should_update =
22
+ height < min_height ||
23
+ (height == min_height && S[min_index] > S[i]);
24
+ if (should_update) {
25
+ min_height = height;
26
+ min_index = i;
27
+ }
28
+ }
29
+ ans = max (ans, min_height);
30
+ done[min_index] = true ;
31
+ }
32
+ return ans;
33
+ }
34
+
35
+ int main () {
36
+ ios_base::sync_with_stdio (false );
37
+ cin.tie (0 ); cout.tie (0 );
38
+
39
+ cin >> N;
40
+ H.assign (N, 0 );
41
+ S.assign (N, 0 );
42
+ for (int i = 0 ; i < N; i++) {
43
+ cin >> H[i] >> S[i];
44
+ }
45
+ cout << solve () << endl;
46
+
47
+ return 0 ;
48
+ }
You can’t perform that action at this time.
0 commit comments