# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
825826 |
2023-08-15T08:34:51 Z |
nasam |
Feast (NOI19_feast) |
C++17 |
|
96 ms |
2680 KB |
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for (int i = (a), _b = (b); i <= _b; i++)
#define FOD(i,b,a) for (int i = (b), _a = (a); i >= _a; i--)
#define FORE(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define ALL(v) (v).begin(), (v).end()
#define BIT(x, i) (((x) >> (i)) & 1)
#define MASK(i) (1LL << (i))
#define CNTBIT(x) __builtin_popcount(x)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define left ___left
#define right ___right
#define pii pair<int, int>
#define pll pair<ll, ll>
#define DEBUG(n, a) FOR (i, 1, n) cout << a[i] << ' '; cout << endl;
#define lob lower_bound // >=
#define upb upper_bound // >
#define endl "\n"
#define NAME "main"
using namespace std;
template<class X, class Y> bool maximize(X &x, Y y){ if (x < y){ x = y; return true; } return false; }
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y){ x = y; return true; } return false; }
#define gogobruhbruh ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
const int MOD = 1e9 + 7;
void add(int &a, int b){ if ((a += b) >= MOD) a -= MOD; }
int sub(int a, int b){ if ((a -= b) < 0) a += MOD; return a; }
int muti(int a, int b){ return (1LL * a * b) % MOD; }
int Pow(int x, int y){ int res = 1; for (; y; y >>= 1){ if (y & 1) res = muti(res, x); x = muti(x, x); } return res; }
const int MAX = 3e5 + 7;
const ll INF = 1e18 + 5;
int num, lim;
ll pre[MAX], dp[MAX], left, right;
#define state pair<ll, int>
void maxx(state &a, state b, ll val, bool ok){
b.fi += val; b.se += ok;
if (a.fi < b.fi)
a = b;
}
state calc(ll cost){
state Max, res;
Max = res = {0, 0};
FOR (i, 1, num){
maxx(res, Max, pre[i] + cost, 1);
maxx(Max, res, -pre[i], 0);
}
return res;
}
void solve(){
left = -left; right = 0;
ll res = 0;
while (left <= right){
ll mid = (left + right) >> 1;
auto[cost, k] = calc(mid);
if (k <= lim){
left = mid + 1;
res = cost - mid * k;
}else
right = mid - 1;
}
cout << res;
}
void read(){
cin >> num >> lim;
ll Min = 0;
FOR (i, 1, num)
cin >> pre[i],
pre[i] += pre[i - 1],
maximize(left, pre[i] - Min),
minimize(Min, pre[i]);
}
int main(){
gogobruhbruh;
file("main");
int test = 1;
// cin >> test;
while (test--)
read(),
solve();
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:30:61: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:90:5: note: in expansion of macro 'file'
90 | file("main");
| ^~~~
feast.cpp:30:95: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
feast.cpp:90:5: note: in expansion of macro 'file'
90 | file("main");
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
2584 KB |
Output is correct |
2 |
Correct |
47 ms |
2628 KB |
Output is correct |
3 |
Correct |
40 ms |
2552 KB |
Output is correct |
4 |
Correct |
49 ms |
2560 KB |
Output is correct |
5 |
Correct |
56 ms |
2624 KB |
Output is correct |
6 |
Correct |
39 ms |
2480 KB |
Output is correct |
7 |
Correct |
39 ms |
2588 KB |
Output is correct |
8 |
Correct |
41 ms |
2628 KB |
Output is correct |
9 |
Correct |
39 ms |
2592 KB |
Output is correct |
10 |
Correct |
40 ms |
2516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
2540 KB |
Output is correct |
2 |
Correct |
25 ms |
2608 KB |
Output is correct |
3 |
Correct |
25 ms |
2612 KB |
Output is correct |
4 |
Correct |
29 ms |
2516 KB |
Output is correct |
5 |
Correct |
39 ms |
2592 KB |
Output is correct |
6 |
Correct |
28 ms |
2544 KB |
Output is correct |
7 |
Correct |
34 ms |
2680 KB |
Output is correct |
8 |
Correct |
47 ms |
2532 KB |
Output is correct |
9 |
Correct |
39 ms |
2516 KB |
Output is correct |
10 |
Correct |
25 ms |
2620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
2632 KB |
Output is correct |
2 |
Correct |
53 ms |
2604 KB |
Output is correct |
3 |
Correct |
58 ms |
2628 KB |
Output is correct |
4 |
Correct |
49 ms |
2520 KB |
Output is correct |
5 |
Correct |
48 ms |
2624 KB |
Output is correct |
6 |
Correct |
48 ms |
2644 KB |
Output is correct |
7 |
Correct |
49 ms |
2528 KB |
Output is correct |
8 |
Correct |
49 ms |
2508 KB |
Output is correct |
9 |
Correct |
49 ms |
2644 KB |
Output is correct |
10 |
Correct |
49 ms |
2592 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 |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 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 |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 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 |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 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 |
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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 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 |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 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 |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
2584 KB |
Output is correct |
2 |
Correct |
47 ms |
2628 KB |
Output is correct |
3 |
Correct |
40 ms |
2552 KB |
Output is correct |
4 |
Correct |
49 ms |
2560 KB |
Output is correct |
5 |
Correct |
56 ms |
2624 KB |
Output is correct |
6 |
Correct |
39 ms |
2480 KB |
Output is correct |
7 |
Correct |
39 ms |
2588 KB |
Output is correct |
8 |
Correct |
41 ms |
2628 KB |
Output is correct |
9 |
Correct |
39 ms |
2592 KB |
Output is correct |
10 |
Correct |
40 ms |
2516 KB |
Output is correct |
11 |
Correct |
39 ms |
2540 KB |
Output is correct |
12 |
Correct |
25 ms |
2608 KB |
Output is correct |
13 |
Correct |
25 ms |
2612 KB |
Output is correct |
14 |
Correct |
29 ms |
2516 KB |
Output is correct |
15 |
Correct |
39 ms |
2592 KB |
Output is correct |
16 |
Correct |
28 ms |
2544 KB |
Output is correct |
17 |
Correct |
34 ms |
2680 KB |
Output is correct |
18 |
Correct |
47 ms |
2532 KB |
Output is correct |
19 |
Correct |
39 ms |
2516 KB |
Output is correct |
20 |
Correct |
25 ms |
2620 KB |
Output is correct |
21 |
Correct |
50 ms |
2632 KB |
Output is correct |
22 |
Correct |
53 ms |
2604 KB |
Output is correct |
23 |
Correct |
58 ms |
2628 KB |
Output is correct |
24 |
Correct |
49 ms |
2520 KB |
Output is correct |
25 |
Correct |
48 ms |
2624 KB |
Output is correct |
26 |
Correct |
48 ms |
2644 KB |
Output is correct |
27 |
Correct |
49 ms |
2528 KB |
Output is correct |
28 |
Correct |
49 ms |
2508 KB |
Output is correct |
29 |
Correct |
49 ms |
2644 KB |
Output is correct |
30 |
Correct |
49 ms |
2592 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
340 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 |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
340 KB |
Output is correct |
49 |
Correct |
0 ms |
212 KB |
Output is correct |
50 |
Correct |
0 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 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 |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
76 ms |
2516 KB |
Output is correct |
62 |
Correct |
96 ms |
2576 KB |
Output is correct |
63 |
Correct |
61 ms |
2524 KB |
Output is correct |
64 |
Correct |
79 ms |
2640 KB |
Output is correct |
65 |
Correct |
86 ms |
2588 KB |
Output is correct |
66 |
Correct |
82 ms |
2632 KB |
Output is correct |
67 |
Correct |
85 ms |
2600 KB |
Output is correct |
68 |
Correct |
50 ms |
2644 KB |
Output is correct |
69 |
Correct |
74 ms |
2596 KB |
Output is correct |
70 |
Correct |
47 ms |
2572 KB |
Output is correct |