// "Complex numbers are better than pears."
// "Always use complex numbers when possible."
// "And plus real numbers are complex numbers anyway so you'll be using them."
// "69 is the largest number you can factorial on a calculator."
// "Therefore, always make your code 69 lines if possible."
// - Some Y1 Rafflesian
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define re real()
#define im imag()
#define mp make_pair
#define pb push_back
#define speed ios_base::sync_with_stdio(false); cin.tie(0)
#define stMx(a,b) a = max(a,b)
#define stMn(a,b) a = min(a,b)
typedef complex<int> ii;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<ii> vii;
typedef set<ii> sii;
#define REP(i, a, b) for(int i = a; i < b; i++)
#define float long double
deque<ii> dq;
int f(ii line, int x) {
return line.re * x + line.im;
}
int query(int x) {
while(dq.size() > 1) {
if(f(dq[0], x) < f(dq[1], x)) dq.pop_front();
else break;
}
return f(dq[0], x);
}
float intersect(int a, int b, int c, int d) {
return (float)(d - b) / (a - c);
}
float intersect(ii p1, ii p2) {
return intersect(p1.re, p1.im, p2.re, p2.im);
}
void ins(int m, int c) {
ii line = ii(m, c);
while(dq.size() > 1) {
int s = dq.size();
if(intersect(dq[s - 1], line) <= intersect(dq[s - 2], line)) dq.pop_back();
else break;
}
dq.push_back(line);
}
int32_t main() {
int N; cin >> N; int T[N], pre[N], nd[N], dp[N];
cin >> T[0]; pre[0] = T[0];
REP(i, 1, N) {
cin >> T[i];
pre[i] = max(T[i], pre[i-1]);
}
ins(-1 * N, 0);
REP(i, 0, N) {
if(i == 0 || pre[i - 1] < T[i]) {
dp[i] = -1 * query(T[i]);
int ptr = i;
while(ptr < N && T[ptr] <= T[i]) ptr++;
ins(ptr - N, -1 * dp[i]);
} else {
dp[i] = dp[i - 1];
}
}
cout << dp[N-1];
}
Compilation message
Discharging.cpp: In function 'int32_t main()':
Discharging.cpp:51:40: warning: unused variable 'nd' [-Wunused-variable]
51 | int N; cin >> N; int T[N], pre[N], nd[N], dp[N];
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
251 ms |
23884 KB |
Output is correct |
17 |
Correct |
265 ms |
23888 KB |
Output is correct |
18 |
Correct |
221 ms |
23892 KB |
Output is correct |
19 |
Correct |
264 ms |
23896 KB |
Output is correct |
20 |
Correct |
279 ms |
23876 KB |
Output is correct |
21 |
Correct |
262 ms |
23892 KB |
Output is correct |
22 |
Correct |
251 ms |
24012 KB |
Output is correct |
23 |
Correct |
286 ms |
23896 KB |
Output is correct |
24 |
Correct |
263 ms |
23876 KB |
Output is correct |
25 |
Correct |
276 ms |
23888 KB |
Output is correct |
26 |
Correct |
300 ms |
23892 KB |
Output is correct |
27 |
Correct |
237 ms |
23776 KB |
Output is correct |
28 |
Correct |
285 ms |
23892 KB |
Output is correct |
29 |
Correct |
278 ms |
23880 KB |
Output is correct |
30 |
Correct |
289 ms |
23876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
384 ms |
23880 KB |
Output is correct |
2 |
Correct |
369 ms |
23892 KB |
Output is correct |
3 |
Correct |
429 ms |
23880 KB |
Output is correct |
4 |
Correct |
365 ms |
23884 KB |
Output is correct |
5 |
Correct |
356 ms |
23788 KB |
Output is correct |
6 |
Correct |
359 ms |
23884 KB |
Output is correct |
7 |
Correct |
353 ms |
23920 KB |
Output is correct |
8 |
Correct |
359 ms |
23940 KB |
Output is correct |
9 |
Correct |
357 ms |
23820 KB |
Output is correct |
10 |
Correct |
351 ms |
23892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
304 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
1 ms |
224 KB |
Output is correct |
41 |
Correct |
1 ms |
304 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
308 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
2 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
251 ms |
23884 KB |
Output is correct |
31 |
Correct |
265 ms |
23888 KB |
Output is correct |
32 |
Correct |
221 ms |
23892 KB |
Output is correct |
33 |
Correct |
264 ms |
23896 KB |
Output is correct |
34 |
Correct |
279 ms |
23876 KB |
Output is correct |
35 |
Correct |
262 ms |
23892 KB |
Output is correct |
36 |
Correct |
251 ms |
24012 KB |
Output is correct |
37 |
Correct |
286 ms |
23896 KB |
Output is correct |
38 |
Correct |
263 ms |
23876 KB |
Output is correct |
39 |
Correct |
276 ms |
23888 KB |
Output is correct |
40 |
Correct |
300 ms |
23892 KB |
Output is correct |
41 |
Correct |
237 ms |
23776 KB |
Output is correct |
42 |
Correct |
285 ms |
23892 KB |
Output is correct |
43 |
Correct |
278 ms |
23880 KB |
Output is correct |
44 |
Correct |
289 ms |
23876 KB |
Output is correct |
45 |
Correct |
384 ms |
23880 KB |
Output is correct |
46 |
Correct |
369 ms |
23892 KB |
Output is correct |
47 |
Correct |
429 ms |
23880 KB |
Output is correct |
48 |
Correct |
365 ms |
23884 KB |
Output is correct |
49 |
Correct |
356 ms |
23788 KB |
Output is correct |
50 |
Correct |
359 ms |
23884 KB |
Output is correct |
51 |
Correct |
353 ms |
23920 KB |
Output is correct |
52 |
Correct |
359 ms |
23940 KB |
Output is correct |
53 |
Correct |
357 ms |
23820 KB |
Output is correct |
54 |
Correct |
351 ms |
23892 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
1 ms |
304 KB |
Output is correct |
63 |
Correct |
1 ms |
212 KB |
Output is correct |
64 |
Correct |
1 ms |
300 KB |
Output is correct |
65 |
Correct |
1 ms |
224 KB |
Output is correct |
66 |
Correct |
1 ms |
304 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
212 KB |
Output is correct |
69 |
Correct |
1 ms |
212 KB |
Output is correct |
70 |
Correct |
1 ms |
212 KB |
Output is correct |
71 |
Correct |
1 ms |
212 KB |
Output is correct |
72 |
Correct |
1 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
212 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
1 ms |
212 KB |
Output is correct |
76 |
Correct |
244 ms |
23924 KB |
Output is correct |
77 |
Correct |
249 ms |
23884 KB |
Output is correct |
78 |
Correct |
231 ms |
23880 KB |
Output is correct |
79 |
Correct |
289 ms |
23880 KB |
Output is correct |
80 |
Correct |
258 ms |
23880 KB |
Output is correct |
81 |
Correct |
237 ms |
23892 KB |
Output is correct |
82 |
Correct |
237 ms |
23900 KB |
Output is correct |
83 |
Correct |
250 ms |
23892 KB |
Output is correct |
84 |
Correct |
240 ms |
23892 KB |
Output is correct |
85 |
Correct |
253 ms |
23892 KB |
Output is correct |
86 |
Correct |
238 ms |
23896 KB |
Output is correct |
87 |
Correct |
255 ms |
23892 KB |
Output is correct |
88 |
Correct |
246 ms |
23960 KB |
Output is correct |
89 |
Correct |
246 ms |
23984 KB |
Output is correct |
90 |
Correct |
241 ms |
23776 KB |
Output is correct |
91 |
Correct |
233 ms |
23880 KB |
Output is correct |
92 |
Correct |
290 ms |
23888 KB |
Output is correct |
93 |
Correct |
282 ms |
23884 KB |
Output is correct |
94 |
Correct |
244 ms |
23992 KB |
Output is correct |
95 |
Correct |
267 ms |
23884 KB |
Output is correct |
96 |
Correct |
233 ms |
23880 KB |
Output is correct |
97 |
Correct |
241 ms |
23896 KB |
Output is correct |
98 |
Correct |
244 ms |
23884 KB |
Output is correct |
99 |
Correct |
238 ms |
23768 KB |
Output is correct |
100 |
Correct |
244 ms |
23820 KB |
Output is correct |