# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
815413 |
2023-08-08T14:51:37 Z |
Mirali7 |
Feast (NOI19_feast) |
C++17 |
|
153 ms |
10596 KB |
#include <iostream>
#include <string>
#include <deque>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#include <stack>
#include <cmath>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>
#include <array>
#include <chrono>
#include <functional>
#include <numeric>
#include <complex>
using namespace std;
#define ll long long
#define ld long double
#define ull uint64_t
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fst first
#define snd second
#define forn(i, n) for (int i = 1; i <= n; i++)
#define dforn(i, a, b) for (int i = a; i <= b; i++)
#define rforn(i, n) for (int i = n; i >= 1; i--)
#define rdforn(i, a, b) for (int i = b; i >= a; i--)
#define sforn(i, a, b, s) for (ll i = a; i <= b; i += s)
#define aforn(v, a) for (auto& v : a)
const int mod = 998244353;
const ld pi = acos(-1);
const ll N = 1e6;
const ll inf = 1e17;
const int iinf = 1 << 30;
const ld dinf = 1e10;
const double eps = 1e-10;
void solve() {
ll n, k;
cin >> n >> k;
vector<ll> a(n + 1);
forn(i, n) {
cin >> a[i];
}
auto calc = [&](ll lambda) {
vector<ll> dp(n + 1), cnt(n + 1);
ll best = 0, bcnt = 1;
forn(i, n) {
dp[i] = dp[i - 1];
cnt[i] = cnt[i - 1];
best += a[i];
if (best - lambda > dp[i]) {
dp[i] = best - lambda;
cnt[i] = bcnt;
}
if (dp[i] > best) {
best = dp[i];
bcnt = cnt[i] + 1;
}
}
return make_pair(dp[n], cnt[n]);
};
ll l = -1, r = 1e13;
while (r - l > 1) {
ll m = (l + r) >> 1;
pll f = calc(m);
if (f.snd <= k) {
r = m;
}
else {
l = m;
}
}
pll cur = calc(r);
ll ans = cur.fst + k * r;
cout << ans << '\n';
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
10112 KB |
Output is correct |
2 |
Correct |
92 ms |
10424 KB |
Output is correct |
3 |
Correct |
90 ms |
10348 KB |
Output is correct |
4 |
Correct |
90 ms |
10296 KB |
Output is correct |
5 |
Correct |
87 ms |
10304 KB |
Output is correct |
6 |
Correct |
89 ms |
10060 KB |
Output is correct |
7 |
Correct |
89 ms |
10120 KB |
Output is correct |
8 |
Correct |
87 ms |
10240 KB |
Output is correct |
9 |
Correct |
88 ms |
10088 KB |
Output is correct |
10 |
Correct |
88 ms |
10364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
8420 KB |
Output is correct |
2 |
Correct |
96 ms |
8756 KB |
Output is correct |
3 |
Correct |
100 ms |
8528 KB |
Output is correct |
4 |
Correct |
84 ms |
8468 KB |
Output is correct |
5 |
Correct |
88 ms |
10140 KB |
Output is correct |
6 |
Correct |
87 ms |
8452 KB |
Output is correct |
7 |
Correct |
87 ms |
8700 KB |
Output is correct |
8 |
Correct |
92 ms |
10424 KB |
Output is correct |
9 |
Correct |
88 ms |
10044 KB |
Output is correct |
10 |
Correct |
84 ms |
8628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
10452 KB |
Output is correct |
2 |
Correct |
130 ms |
10348 KB |
Output is correct |
3 |
Correct |
112 ms |
10408 KB |
Output is correct |
4 |
Correct |
110 ms |
10312 KB |
Output is correct |
5 |
Correct |
116 ms |
10412 KB |
Output is correct |
6 |
Correct |
126 ms |
10424 KB |
Output is correct |
7 |
Correct |
117 ms |
10552 KB |
Output is correct |
8 |
Correct |
121 ms |
10412 KB |
Output is correct |
9 |
Correct |
115 ms |
10596 KB |
Output is correct |
10 |
Correct |
116 ms |
10516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
320 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
324 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
356 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
468 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 |
328 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
10112 KB |
Output is correct |
2 |
Correct |
92 ms |
10424 KB |
Output is correct |
3 |
Correct |
90 ms |
10348 KB |
Output is correct |
4 |
Correct |
90 ms |
10296 KB |
Output is correct |
5 |
Correct |
87 ms |
10304 KB |
Output is correct |
6 |
Correct |
89 ms |
10060 KB |
Output is correct |
7 |
Correct |
89 ms |
10120 KB |
Output is correct |
8 |
Correct |
87 ms |
10240 KB |
Output is correct |
9 |
Correct |
88 ms |
10088 KB |
Output is correct |
10 |
Correct |
88 ms |
10364 KB |
Output is correct |
11 |
Correct |
87 ms |
8420 KB |
Output is correct |
12 |
Correct |
96 ms |
8756 KB |
Output is correct |
13 |
Correct |
100 ms |
8528 KB |
Output is correct |
14 |
Correct |
84 ms |
8468 KB |
Output is correct |
15 |
Correct |
88 ms |
10140 KB |
Output is correct |
16 |
Correct |
87 ms |
8452 KB |
Output is correct |
17 |
Correct |
87 ms |
8700 KB |
Output is correct |
18 |
Correct |
92 ms |
10424 KB |
Output is correct |
19 |
Correct |
88 ms |
10044 KB |
Output is correct |
20 |
Correct |
84 ms |
8628 KB |
Output is correct |
21 |
Correct |
113 ms |
10452 KB |
Output is correct |
22 |
Correct |
130 ms |
10348 KB |
Output is correct |
23 |
Correct |
112 ms |
10408 KB |
Output is correct |
24 |
Correct |
110 ms |
10312 KB |
Output is correct |
25 |
Correct |
116 ms |
10412 KB |
Output is correct |
26 |
Correct |
126 ms |
10424 KB |
Output is correct |
27 |
Correct |
117 ms |
10552 KB |
Output is correct |
28 |
Correct |
121 ms |
10412 KB |
Output is correct |
29 |
Correct |
115 ms |
10596 KB |
Output is correct |
30 |
Correct |
116 ms |
10516 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
320 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
320 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
0 ms |
212 KB |
Output is correct |
45 |
Correct |
0 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
324 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
356 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
468 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
328 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
146 ms |
10248 KB |
Output is correct |
62 |
Correct |
144 ms |
10496 KB |
Output is correct |
63 |
Correct |
131 ms |
10232 KB |
Output is correct |
64 |
Correct |
142 ms |
10440 KB |
Output is correct |
65 |
Correct |
150 ms |
10420 KB |
Output is correct |
66 |
Correct |
141 ms |
10400 KB |
Output is correct |
67 |
Correct |
153 ms |
10284 KB |
Output is correct |
68 |
Correct |
113 ms |
10472 KB |
Output is correct |
69 |
Correct |
110 ms |
10316 KB |
Output is correct |
70 |
Correct |
109 ms |
10248 KB |
Output is correct |