답안 #1094226

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094226 2024-09-29T03:55:37 Z Trisanu_Das Feast (NOI19_feast) C++17
100 / 100
96 ms 10476 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
 
int n, k, a[300005];
pair<int, int> dp[300005];
 
pair<int, int> calc(int mid){
    pair<int, int> curr(0,0);
    for(int i = 1; i <= n; i++){
        dp[i] = max(dp[i - 1], {curr.ff + a[i] - mid, curr.ss + 1});
        curr = max(curr, {dp[i].ff - a[i], dp[i].ss});
    }
    return dp[n];
}
 
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    for(int i = 1; i <= n; i++) a[i] += a[i - 1];
    int l = 0, r = 3e14;
    while(l < r){
        int mid = (l + r + 1) / 2;
        if(calc(mid).ss >= k) l = mid;
        else r = mid - 1;
    }
    cout << calc(l).ff + l * k << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 9888 KB Output is correct
2 Correct 41 ms 10072 KB Output is correct
3 Correct 41 ms 10200 KB Output is correct
4 Correct 41 ms 10072 KB Output is correct
5 Correct 43 ms 10068 KB Output is correct
6 Correct 40 ms 10064 KB Output is correct
7 Correct 40 ms 9876 KB Output is correct
8 Correct 41 ms 10076 KB Output is correct
9 Correct 40 ms 10076 KB Output is correct
10 Correct 44 ms 10068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 8280 KB Output is correct
2 Correct 45 ms 8540 KB Output is correct
3 Correct 39 ms 8284 KB Output is correct
4 Correct 36 ms 8280 KB Output is correct
5 Correct 49 ms 10076 KB Output is correct
6 Correct 40 ms 8408 KB Output is correct
7 Correct 41 ms 8684 KB Output is correct
8 Correct 60 ms 10332 KB Output is correct
9 Correct 51 ms 10040 KB Output is correct
10 Correct 36 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 10320 KB Output is correct
2 Correct 64 ms 10296 KB Output is correct
3 Correct 63 ms 10324 KB Output is correct
4 Correct 61 ms 10332 KB Output is correct
5 Correct 65 ms 10332 KB Output is correct
6 Correct 63 ms 10456 KB Output is correct
7 Correct 64 ms 10320 KB Output is correct
8 Correct 67 ms 10332 KB Output is correct
9 Correct 63 ms 10332 KB Output is correct
10 Correct 65 ms 10324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 344 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 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 468 KB Output is correct
6 Correct 0 ms 344 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 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 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 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 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 600 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 40 ms 9888 KB Output is correct
2 Correct 41 ms 10072 KB Output is correct
3 Correct 41 ms 10200 KB Output is correct
4 Correct 41 ms 10072 KB Output is correct
5 Correct 43 ms 10068 KB Output is correct
6 Correct 40 ms 10064 KB Output is correct
7 Correct 40 ms 9876 KB Output is correct
8 Correct 41 ms 10076 KB Output is correct
9 Correct 40 ms 10076 KB Output is correct
10 Correct 44 ms 10068 KB Output is correct
11 Correct 39 ms 8280 KB Output is correct
12 Correct 45 ms 8540 KB Output is correct
13 Correct 39 ms 8284 KB Output is correct
14 Correct 36 ms 8280 KB Output is correct
15 Correct 49 ms 10076 KB Output is correct
16 Correct 40 ms 8408 KB Output is correct
17 Correct 41 ms 8684 KB Output is correct
18 Correct 60 ms 10332 KB Output is correct
19 Correct 51 ms 10040 KB Output is correct
20 Correct 36 ms 8540 KB Output is correct
21 Correct 65 ms 10320 KB Output is correct
22 Correct 64 ms 10296 KB Output is correct
23 Correct 63 ms 10324 KB Output is correct
24 Correct 61 ms 10332 KB Output is correct
25 Correct 65 ms 10332 KB Output is correct
26 Correct 63 ms 10456 KB Output is correct
27 Correct 64 ms 10320 KB Output is correct
28 Correct 67 ms 10332 KB Output is correct
29 Correct 63 ms 10332 KB Output is correct
30 Correct 65 ms 10324 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 468 KB Output is correct
36 Correct 0 ms 344 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 348 KB Output is correct
41 Correct 0 ms 348 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 348 KB Output is correct
45 Correct 0 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 348 KB Output is correct
50 Correct 0 ms 344 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 348 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 600 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 89 ms 10292 KB Output is correct
62 Correct 89 ms 10324 KB Output is correct
63 Correct 74 ms 10072 KB Output is correct
64 Correct 95 ms 10432 KB Output is correct
65 Correct 96 ms 10324 KB Output is correct
66 Correct 92 ms 10324 KB Output is correct
67 Correct 91 ms 10284 KB Output is correct
68 Correct 66 ms 10476 KB Output is correct
69 Correct 63 ms 10064 KB Output is correct
70 Correct 63 ms 10076 KB Output is correct