#include <iostream>
#include <deque>
#include <vector>
#define ll long long
#define vi vector<ll>
#define pii pair<ll, ll>
#define fst first
#define snd second
#define vpi vector<pii>
using namespace std;
const long double EPS = 1e-9;
int n;
ll ar[1000001];
vpi dt;
deque<pii> s;
long double xIntercept(pii a, pii b)
{
return (long double)(b.snd - a.snd) / (a.fst - b.fst);
}
ll eval(ll x, pii l) {return l.fst * x + l.snd;}
int main()
{
ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
int curMax = 0;
for (int i = 0; i < n; i++)
{
cin >> ar[i];
if (ar[i] > ar[curMax])
{
dt.push_back({ar[curMax], i - curMax});
curMax = i;
}
}
dt.push_back({ar[curMax], n - curMax});
s.push_back({n, 0});
int curSZ = 0;
for (int i = 0; i < dt.size(); i++)
{
// cout << dt[i].fst << " " << dt[i].snd << "\n";
while (s.size() > 1 && eval(dt[i].fst, s[0]) >= eval(dt[i].fst, s[1])) {s.pop_front();}
curSZ += dt[i].snd;
pii l = {n - curSZ, eval(dt[i].fst, s[0])};
while (s.size() > 1 && xIntercept(s.back(), l) - xIntercept(s.back(), s[s.size() - 2]) <= -EPS) {s.pop_back();}
s.push_back(l);
}
cout << s.back().snd << "\n";
return 0;
}
Compilation message
Discharging.cpp: In function 'int main()':
Discharging.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < dt.size(); i++)
~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
276 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
404 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
404 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
141 ms |
19588 KB |
Output is correct |
17 |
Correct |
165 ms |
21316 KB |
Output is correct |
18 |
Correct |
130 ms |
20684 KB |
Output is correct |
19 |
Correct |
165 ms |
21084 KB |
Output is correct |
20 |
Correct |
155 ms |
21716 KB |
Output is correct |
21 |
Correct |
153 ms |
21076 KB |
Output is correct |
22 |
Correct |
150 ms |
20156 KB |
Output is correct |
23 |
Correct |
200 ms |
30036 KB |
Output is correct |
24 |
Correct |
173 ms |
30700 KB |
Output is correct |
25 |
Correct |
167 ms |
30936 KB |
Output is correct |
26 |
Correct |
170 ms |
29332 KB |
Output is correct |
27 |
Correct |
141 ms |
20336 KB |
Output is correct |
28 |
Correct |
154 ms |
21604 KB |
Output is correct |
29 |
Correct |
164 ms |
30740 KB |
Output is correct |
30 |
Correct |
187 ms |
29604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
17784 KB |
Output is correct |
2 |
Correct |
174 ms |
17900 KB |
Output is correct |
3 |
Correct |
171 ms |
17784 KB |
Output is correct |
4 |
Correct |
170 ms |
17784 KB |
Output is correct |
5 |
Correct |
196 ms |
17844 KB |
Output is correct |
6 |
Correct |
183 ms |
17876 KB |
Output is correct |
7 |
Correct |
158 ms |
17864 KB |
Output is correct |
8 |
Correct |
176 ms |
17904 KB |
Output is correct |
9 |
Correct |
169 ms |
17776 KB |
Output is correct |
10 |
Correct |
169 ms |
17864 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
276 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
396 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
404 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
416 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
412 KB |
Output is correct |
36 |
Correct |
1 ms |
384 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
1 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
1 ms |
384 KB |
Output is correct |
41 |
Correct |
1 ms |
384 KB |
Output is correct |
42 |
Correct |
1 ms |
384 KB |
Output is correct |
43 |
Correct |
1 ms |
384 KB |
Output is correct |
44 |
Correct |
1 ms |
384 KB |
Output is correct |
45 |
Correct |
1 ms |
384 KB |
Output is correct |
46 |
Correct |
1 ms |
384 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
408 KB |
Output is correct |
49 |
Correct |
1 ms |
384 KB |
Output is correct |
50 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
276 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
396 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
404 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
141 ms |
19588 KB |
Output is correct |
31 |
Correct |
165 ms |
21316 KB |
Output is correct |
32 |
Correct |
130 ms |
20684 KB |
Output is correct |
33 |
Correct |
165 ms |
21084 KB |
Output is correct |
34 |
Correct |
155 ms |
21716 KB |
Output is correct |
35 |
Correct |
153 ms |
21076 KB |
Output is correct |
36 |
Correct |
150 ms |
20156 KB |
Output is correct |
37 |
Correct |
200 ms |
30036 KB |
Output is correct |
38 |
Correct |
173 ms |
30700 KB |
Output is correct |
39 |
Correct |
167 ms |
30936 KB |
Output is correct |
40 |
Correct |
170 ms |
29332 KB |
Output is correct |
41 |
Correct |
141 ms |
20336 KB |
Output is correct |
42 |
Correct |
154 ms |
21604 KB |
Output is correct |
43 |
Correct |
164 ms |
30740 KB |
Output is correct |
44 |
Correct |
187 ms |
29604 KB |
Output is correct |
45 |
Correct |
165 ms |
17784 KB |
Output is correct |
46 |
Correct |
174 ms |
17900 KB |
Output is correct |
47 |
Correct |
171 ms |
17784 KB |
Output is correct |
48 |
Correct |
170 ms |
17784 KB |
Output is correct |
49 |
Correct |
196 ms |
17844 KB |
Output is correct |
50 |
Correct |
183 ms |
17876 KB |
Output is correct |
51 |
Correct |
158 ms |
17864 KB |
Output is correct |
52 |
Correct |
176 ms |
17904 KB |
Output is correct |
53 |
Correct |
169 ms |
17776 KB |
Output is correct |
54 |
Correct |
169 ms |
17864 KB |
Output is correct |
55 |
Correct |
1 ms |
416 KB |
Output is correct |
56 |
Correct |
1 ms |
384 KB |
Output is correct |
57 |
Correct |
1 ms |
384 KB |
Output is correct |
58 |
Correct |
1 ms |
384 KB |
Output is correct |
59 |
Correct |
1 ms |
384 KB |
Output is correct |
60 |
Correct |
1 ms |
412 KB |
Output is correct |
61 |
Correct |
1 ms |
384 KB |
Output is correct |
62 |
Correct |
1 ms |
384 KB |
Output is correct |
63 |
Correct |
1 ms |
384 KB |
Output is correct |
64 |
Correct |
1 ms |
384 KB |
Output is correct |
65 |
Correct |
1 ms |
384 KB |
Output is correct |
66 |
Correct |
1 ms |
384 KB |
Output is correct |
67 |
Correct |
1 ms |
384 KB |
Output is correct |
68 |
Correct |
1 ms |
384 KB |
Output is correct |
69 |
Correct |
1 ms |
384 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1 ms |
384 KB |
Output is correct |
72 |
Correct |
1 ms |
384 KB |
Output is correct |
73 |
Correct |
1 ms |
408 KB |
Output is correct |
74 |
Correct |
1 ms |
384 KB |
Output is correct |
75 |
Correct |
1 ms |
384 KB |
Output is correct |
76 |
Correct |
133 ms |
14156 KB |
Output is correct |
77 |
Correct |
125 ms |
14232 KB |
Output is correct |
78 |
Correct |
127 ms |
13556 KB |
Output is correct |
79 |
Correct |
122 ms |
13816 KB |
Output is correct |
80 |
Correct |
126 ms |
14460 KB |
Output is correct |
81 |
Correct |
136 ms |
13720 KB |
Output is correct |
82 |
Correct |
139 ms |
13816 KB |
Output is correct |
83 |
Correct |
123 ms |
14236 KB |
Output is correct |
84 |
Correct |
127 ms |
13940 KB |
Output is correct |
85 |
Correct |
136 ms |
14296 KB |
Output is correct |
86 |
Correct |
122 ms |
13688 KB |
Output is correct |
87 |
Correct |
118 ms |
13536 KB |
Output is correct |
88 |
Correct |
127 ms |
13896 KB |
Output is correct |
89 |
Correct |
128 ms |
13688 KB |
Output is correct |
90 |
Correct |
125 ms |
13692 KB |
Output is correct |
91 |
Correct |
125 ms |
13432 KB |
Output is correct |
92 |
Correct |
174 ms |
23048 KB |
Output is correct |
93 |
Correct |
159 ms |
21352 KB |
Output is correct |
94 |
Correct |
133 ms |
13168 KB |
Output is correct |
95 |
Correct |
151 ms |
14584 KB |
Output is correct |
96 |
Correct |
132 ms |
13456 KB |
Output is correct |
97 |
Correct |
129 ms |
13788 KB |
Output is correct |
98 |
Correct |
131 ms |
13984 KB |
Output is correct |
99 |
Correct |
193 ms |
13612 KB |
Output is correct |
100 |
Correct |
142 ms |
13724 KB |
Output is correct |