# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
534410 |
2022-03-08T06:45:22 Z |
idas |
Feast (NOI19_feast) |
C++11 |
|
119 ms |
12744 KB |
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define f first
#define s second
#define pb push_back
#define sz(x) ((int)((x).size()))
#define le(vec) vec[vec.size()-1]
#define all(x) (x).begin(), (x).end()
#define TSTS int ttt; cin >> ttt; while(ttt--) solve()
using namespace std;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<long double, long double> pdd;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;
const int INF=1e9, MOD=1e9+7, mod=998244353;
const ll LINF=1e18;
void setIO()
{
FAST_IO;
}
void setIO(string s)
{
FAST_IO;
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
#define int long long
const int N=3e5+10;
int n, k;
ll a[N], p[N];
pair<ll, int> dp[N];
void calc(ll x)
{
//FOR(i, 0, n+1) dp[i]={0,0};
pair<ll, int> best={0,0};
FOR(i, 1, n+1)
{
dp[i]=max(dp[i-1], {best.f-x+p[i],best.s-1});
best=max(best, {dp[i].f-p[i],dp[i].s});
}
}
signed main()
{
setIO();
cin >> n >> k;
FOR(i, 1, n+1) cin >> a[i];
FOR(i, 1, n+1) p[i]=p[i-1]+a[i];
ll l=0, r=1e13;
while(l<r){
ll m=(l+r)/2;
calc(m);
if(-dp[n].s<=k) r=m;
else l=m+1;
}
calc(l);
ll ans=dp[n].f-dp[n].s*l;
cout << ans;
}
Compilation message
feast.cpp: In function 'void setIO(std::string)':
feast.cpp:32:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | freopen((s+".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:33:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | freopen((s+".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
9400 KB |
Output is correct |
2 |
Correct |
61 ms |
9572 KB |
Output is correct |
3 |
Correct |
58 ms |
9584 KB |
Output is correct |
4 |
Correct |
60 ms |
9504 KB |
Output is correct |
5 |
Correct |
60 ms |
9496 KB |
Output is correct |
6 |
Correct |
61 ms |
9408 KB |
Output is correct |
7 |
Correct |
59 ms |
9360 KB |
Output is correct |
8 |
Correct |
61 ms |
9488 KB |
Output is correct |
9 |
Correct |
58 ms |
9332 KB |
Output is correct |
10 |
Correct |
58 ms |
9528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
9464 KB |
Output is correct |
2 |
Correct |
55 ms |
9680 KB |
Output is correct |
3 |
Correct |
54 ms |
9420 KB |
Output is correct |
4 |
Correct |
52 ms |
9548 KB |
Output is correct |
5 |
Correct |
58 ms |
9380 KB |
Output is correct |
6 |
Correct |
49 ms |
9444 KB |
Output is correct |
7 |
Correct |
53 ms |
9688 KB |
Output is correct |
8 |
Correct |
63 ms |
9640 KB |
Output is correct |
9 |
Correct |
61 ms |
9472 KB |
Output is correct |
10 |
Correct |
58 ms |
9624 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
9528 KB |
Output is correct |
2 |
Correct |
78 ms |
12352 KB |
Output is correct |
3 |
Correct |
77 ms |
12584 KB |
Output is correct |
4 |
Correct |
78 ms |
12408 KB |
Output is correct |
5 |
Correct |
94 ms |
12480 KB |
Output is correct |
6 |
Correct |
79 ms |
12608 KB |
Output is correct |
7 |
Correct |
77 ms |
12608 KB |
Output is correct |
8 |
Correct |
80 ms |
12484 KB |
Output is correct |
9 |
Correct |
81 ms |
12712 KB |
Output is correct |
10 |
Correct |
81 ms |
12716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
328 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
352 KB |
Output is correct |
30 |
Correct |
1 ms |
360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
9400 KB |
Output is correct |
2 |
Correct |
61 ms |
9572 KB |
Output is correct |
3 |
Correct |
58 ms |
9584 KB |
Output is correct |
4 |
Correct |
60 ms |
9504 KB |
Output is correct |
5 |
Correct |
60 ms |
9496 KB |
Output is correct |
6 |
Correct |
61 ms |
9408 KB |
Output is correct |
7 |
Correct |
59 ms |
9360 KB |
Output is correct |
8 |
Correct |
61 ms |
9488 KB |
Output is correct |
9 |
Correct |
58 ms |
9332 KB |
Output is correct |
10 |
Correct |
58 ms |
9528 KB |
Output is correct |
11 |
Correct |
54 ms |
9464 KB |
Output is correct |
12 |
Correct |
55 ms |
9680 KB |
Output is correct |
13 |
Correct |
54 ms |
9420 KB |
Output is correct |
14 |
Correct |
52 ms |
9548 KB |
Output is correct |
15 |
Correct |
58 ms |
9380 KB |
Output is correct |
16 |
Correct |
49 ms |
9444 KB |
Output is correct |
17 |
Correct |
53 ms |
9688 KB |
Output is correct |
18 |
Correct |
63 ms |
9640 KB |
Output is correct |
19 |
Correct |
61 ms |
9472 KB |
Output is correct |
20 |
Correct |
58 ms |
9624 KB |
Output is correct |
21 |
Correct |
78 ms |
9528 KB |
Output is correct |
22 |
Correct |
78 ms |
12352 KB |
Output is correct |
23 |
Correct |
77 ms |
12584 KB |
Output is correct |
24 |
Correct |
78 ms |
12408 KB |
Output is correct |
25 |
Correct |
94 ms |
12480 KB |
Output is correct |
26 |
Correct |
79 ms |
12608 KB |
Output is correct |
27 |
Correct |
77 ms |
12608 KB |
Output is correct |
28 |
Correct |
80 ms |
12484 KB |
Output is correct |
29 |
Correct |
81 ms |
12712 KB |
Output is correct |
30 |
Correct |
81 ms |
12716 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
324 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
320 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
1 ms |
320 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
1 ms |
316 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
1 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
54 |
Correct |
1 ms |
328 KB |
Output is correct |
55 |
Correct |
1 ms |
332 KB |
Output is correct |
56 |
Correct |
1 ms |
332 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
352 KB |
Output is correct |
60 |
Correct |
1 ms |
360 KB |
Output is correct |
61 |
Correct |
115 ms |
12372 KB |
Output is correct |
62 |
Correct |
115 ms |
12700 KB |
Output is correct |
63 |
Correct |
88 ms |
12356 KB |
Output is correct |
64 |
Correct |
113 ms |
12744 KB |
Output is correct |
65 |
Correct |
119 ms |
12716 KB |
Output is correct |
66 |
Correct |
112 ms |
12488 KB |
Output is correct |
67 |
Correct |
113 ms |
12340 KB |
Output is correct |
68 |
Correct |
79 ms |
12740 KB |
Output is correct |
69 |
Correct |
79 ms |
12440 KB |
Output is correct |
70 |
Correct |
75 ms |
12356 KB |
Output is correct |