답안 #1104206

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1104206 2024-10-23T08:57:14 Z nasir_bashirov Feast (NOI19_feast) C++11
100 / 100
216 ms 15176 KB
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define db long double
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define int long long

const int sz = 3e5 + 5;
int n, k, a[sz];
pii dp[sz][2];

void calc(int mid){
    dp[1][0] = {0, 0}, dp[1][1] = {a[1] - mid, 1};
    for(int i = 2; i <= n; i++){
        dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] = max(make_pair(dp[i - 1][0].first + a[i] - mid, dp[i - 1][0].second + 1), make_pair(dp[i - 1][1].first + a[i], dp[i - 1][1].second));
    }
}

void fmain(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int l = 0, r = 1e15, res = 0;
    while(l <= r){
        int mid = (l + r) / 2;
        calc(mid);
        if(max(dp[n][0], dp[n][1]).second >= k){
            l = mid + 1;
            res = mid;
        } 
        else{
            r = mid - 1;
        }
    }
    calc(res);
    cout << res * k + max(dp[n][0], dp[n][1]).first;
}

signed main(){
    int tmr = 1;
    //cin >> tmr;
    while(tmr--){
        fmain();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 11848 KB Output is correct
2 Correct 101 ms 12668 KB Output is correct
3 Correct 96 ms 12204 KB Output is correct
4 Correct 103 ms 12364 KB Output is correct
5 Correct 95 ms 13764 KB Output is correct
6 Correct 102 ms 11960 KB Output is correct
7 Correct 92 ms 12104 KB Output is correct
8 Correct 94 ms 12104 KB Output is correct
9 Correct 92 ms 11956 KB Output is correct
10 Correct 94 ms 11952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 12104 KB Output is correct
2 Correct 77 ms 12104 KB Output is correct
3 Correct 67 ms 12104 KB Output is correct
4 Correct 67 ms 12052 KB Output is correct
5 Correct 102 ms 13128 KB Output is correct
6 Correct 66 ms 12104 KB Output is correct
7 Correct 69 ms 12476 KB Output is correct
8 Correct 112 ms 14152 KB Output is correct
9 Correct 101 ms 11848 KB Output is correct
10 Correct 70 ms 12108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 11952 KB Output is correct
2 Correct 129 ms 13384 KB Output is correct
3 Correct 140 ms 13544 KB Output is correct
4 Correct 134 ms 14164 KB Output is correct
5 Correct 127 ms 13384 KB Output is correct
6 Correct 135 ms 12108 KB Output is correct
7 Correct 130 ms 13384 KB Output is correct
8 Correct 132 ms 13388 KB Output is correct
9 Correct 138 ms 13552 KB Output is correct
10 Correct 136 ms 14664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2496 KB Output is correct
20 Correct 2 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2384 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2384 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 1 ms 2384 KB Output is correct
16 Correct 1 ms 2384 KB Output is correct
17 Correct 1 ms 2384 KB Output is correct
18 Correct 1 ms 2384 KB Output is correct
19 Correct 1 ms 2496 KB Output is correct
20 Correct 2 ms 2384 KB Output is correct
21 Correct 3 ms 2384 KB Output is correct
22 Correct 3 ms 2384 KB Output is correct
23 Correct 2 ms 2508 KB Output is correct
24 Correct 2 ms 2384 KB Output is correct
25 Correct 2 ms 2384 KB Output is correct
26 Correct 3 ms 2384 KB Output is correct
27 Correct 3 ms 2384 KB Output is correct
28 Correct 2 ms 2384 KB Output is correct
29 Correct 2 ms 2384 KB Output is correct
30 Correct 3 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 99 ms 11848 KB Output is correct
2 Correct 101 ms 12668 KB Output is correct
3 Correct 96 ms 12204 KB Output is correct
4 Correct 103 ms 12364 KB Output is correct
5 Correct 95 ms 13764 KB Output is correct
6 Correct 102 ms 11960 KB Output is correct
7 Correct 92 ms 12104 KB Output is correct
8 Correct 94 ms 12104 KB Output is correct
9 Correct 92 ms 11956 KB Output is correct
10 Correct 94 ms 11952 KB Output is correct
11 Correct 67 ms 12104 KB Output is correct
12 Correct 77 ms 12104 KB Output is correct
13 Correct 67 ms 12104 KB Output is correct
14 Correct 67 ms 12052 KB Output is correct
15 Correct 102 ms 13128 KB Output is correct
16 Correct 66 ms 12104 KB Output is correct
17 Correct 69 ms 12476 KB Output is correct
18 Correct 112 ms 14152 KB Output is correct
19 Correct 101 ms 11848 KB Output is correct
20 Correct 70 ms 12108 KB Output is correct
21 Correct 129 ms 11952 KB Output is correct
22 Correct 129 ms 13384 KB Output is correct
23 Correct 140 ms 13544 KB Output is correct
24 Correct 134 ms 14164 KB Output is correct
25 Correct 127 ms 13384 KB Output is correct
26 Correct 135 ms 12108 KB Output is correct
27 Correct 130 ms 13384 KB Output is correct
28 Correct 132 ms 13388 KB Output is correct
29 Correct 138 ms 13552 KB Output is correct
30 Correct 136 ms 14664 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 1 ms 2384 KB Output is correct
36 Correct 1 ms 2384 KB Output is correct
37 Correct 1 ms 2384 KB Output is correct
38 Correct 1 ms 2384 KB Output is correct
39 Correct 1 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 1 ms 2384 KB Output is correct
42 Correct 1 ms 2384 KB Output is correct
43 Correct 1 ms 2384 KB Output is correct
44 Correct 1 ms 2384 KB Output is correct
45 Correct 1 ms 2384 KB Output is correct
46 Correct 1 ms 2384 KB Output is correct
47 Correct 1 ms 2384 KB Output is correct
48 Correct 1 ms 2384 KB Output is correct
49 Correct 1 ms 2496 KB Output is correct
50 Correct 2 ms 2384 KB Output is correct
51 Correct 3 ms 2384 KB Output is correct
52 Correct 3 ms 2384 KB Output is correct
53 Correct 2 ms 2508 KB Output is correct
54 Correct 2 ms 2384 KB Output is correct
55 Correct 2 ms 2384 KB Output is correct
56 Correct 3 ms 2384 KB Output is correct
57 Correct 3 ms 2384 KB Output is correct
58 Correct 2 ms 2384 KB Output is correct
59 Correct 2 ms 2384 KB Output is correct
60 Correct 3 ms 2508 KB Output is correct
61 Correct 163 ms 14920 KB Output is correct
62 Correct 216 ms 15176 KB Output is correct
63 Correct 152 ms 14724 KB Output is correct
64 Correct 178 ms 15064 KB Output is correct
65 Correct 175 ms 15144 KB Output is correct
66 Correct 179 ms 14920 KB Output is correct
67 Correct 188 ms 15004 KB Output is correct
68 Correct 139 ms 15140 KB Output is correct
69 Correct 153 ms 14888 KB Output is correct
70 Correct 140 ms 15016 KB Output is correct