답안 #1079920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1079920 2024-08-29T03:30:18 Z hqminhuwu Feast (NOI19_feast) C++14
100 / 100
93 ms 12428 KB
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;

#define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

template<class X, class Y>
    bool minz(X &x, const Y &y) {
        if (x > y) {
            x = y;
            return true;
        } return false;
    }
template<class X, class Y>
    bool maxz(X &x, const Y &y) {
        if (x < y) {
            x = y;
            return true;
        } return false;
    }

const int N = 5e5 + 5;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;

ll dp[N], cnt[N], a[N], n, k;

void calc (ll x){
    ll mx = -x, mxcnt = 0;
    forr (i, 1, n){
        dp[i] = dp[i - 1];
        cnt[i] = cnt[i - 1];

        if (maxz(dp[i], mx + a[i])){
            cnt[i] = mxcnt + 1;
        }

        if (maxz(mx, dp[i] - a[i] - x)){
            mxcnt = cnt[i];
        }
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifdef hqm
        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    #endif

    cin >> n >> k;

    forr (i, 1, n){
        cin >> a[i];
        a[i] += a[i - 1];
    }
    
    ll l = 0, r = mod * n;

    while (l < r){
        ll mid = (l + r + 1) >> 1;
        calc(mid);

        if (cnt[n] < k)
            r = mid - 1;
        else l = mid;
    }

    calc(l);

    //cout << l << " " << dp[n] << " " << cnt[n] << endl;
    cout << dp[n] + l * k;

    return 0;
}
/*



*/

# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 12188 KB Output is correct
2 Correct 42 ms 12016 KB Output is correct
3 Correct 42 ms 12212 KB Output is correct
4 Correct 74 ms 12104 KB Output is correct
5 Correct 44 ms 12028 KB Output is correct
6 Correct 40 ms 12196 KB Output is correct
7 Correct 73 ms 12188 KB Output is correct
8 Correct 41 ms 12124 KB Output is correct
9 Correct 50 ms 12116 KB Output is correct
10 Correct 41 ms 12112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 10348 KB Output is correct
2 Correct 40 ms 10332 KB Output is correct
3 Correct 42 ms 10356 KB Output is correct
4 Correct 52 ms 10324 KB Output is correct
5 Correct 36 ms 12124 KB Output is correct
6 Correct 28 ms 10332 KB Output is correct
7 Correct 31 ms 10488 KB Output is correct
8 Correct 37 ms 12104 KB Output is correct
9 Correct 37 ms 12124 KB Output is correct
10 Correct 30 ms 10328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 12276 KB Output is correct
2 Correct 86 ms 12368 KB Output is correct
3 Correct 52 ms 12408 KB Output is correct
4 Correct 52 ms 12376 KB Output is correct
5 Correct 59 ms 12408 KB Output is correct
6 Correct 87 ms 12428 KB Output is correct
7 Correct 57 ms 12372 KB Output is correct
8 Correct 53 ms 12396 KB Output is correct
9 Correct 51 ms 12368 KB Output is correct
10 Correct 52 ms 12372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 464 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 464 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 464 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 464 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 476 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 12188 KB Output is correct
2 Correct 42 ms 12016 KB Output is correct
3 Correct 42 ms 12212 KB Output is correct
4 Correct 74 ms 12104 KB Output is correct
5 Correct 44 ms 12028 KB Output is correct
6 Correct 40 ms 12196 KB Output is correct
7 Correct 73 ms 12188 KB Output is correct
8 Correct 41 ms 12124 KB Output is correct
9 Correct 50 ms 12116 KB Output is correct
10 Correct 41 ms 12112 KB Output is correct
11 Correct 34 ms 10348 KB Output is correct
12 Correct 40 ms 10332 KB Output is correct
13 Correct 42 ms 10356 KB Output is correct
14 Correct 52 ms 10324 KB Output is correct
15 Correct 36 ms 12124 KB Output is correct
16 Correct 28 ms 10332 KB Output is correct
17 Correct 31 ms 10488 KB Output is correct
18 Correct 37 ms 12104 KB Output is correct
19 Correct 37 ms 12124 KB Output is correct
20 Correct 30 ms 10328 KB Output is correct
21 Correct 53 ms 12276 KB Output is correct
22 Correct 86 ms 12368 KB Output is correct
23 Correct 52 ms 12408 KB Output is correct
24 Correct 52 ms 12376 KB Output is correct
25 Correct 59 ms 12408 KB Output is correct
26 Correct 87 ms 12428 KB Output is correct
27 Correct 57 ms 12372 KB Output is correct
28 Correct 53 ms 12396 KB Output is correct
29 Correct 51 ms 12368 KB Output is correct
30 Correct 52 ms 12372 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 0 ms 348 KB Output is correct
40 Correct 0 ms 464 KB Output is correct
41 Correct 1 ms 344 KB Output is correct
42 Correct 1 ms 464 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 464 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 1 ms 344 KB Output is correct
52 Correct 1 ms 476 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 1 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 344 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 85 ms 12372 KB Output is correct
62 Correct 88 ms 12276 KB Output is correct
63 Correct 69 ms 12368 KB Output is correct
64 Correct 89 ms 12272 KB Output is correct
65 Correct 88 ms 12272 KB Output is correct
66 Correct 93 ms 12392 KB Output is correct
67 Correct 86 ms 12376 KB Output is correct
68 Correct 55 ms 12268 KB Output is correct
69 Correct 53 ms 12368 KB Output is correct
70 Correct 50 ms 12116 KB Output is correct