#include <iostream> //cin, cout
/*
#include <fstream>
std::ifstream cin ("ex.in");
std::ofstream cout ("ex.out");
*/
// includes
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <unordered_set>
#include <stack>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>
#include <chrono>
#include <bitset>
#include <complex>
//usings
using namespace std;
using namespace __gnu_pbds;
// misc
#define ll long long
#define ld long double
#define pb push_back
#define pq priority_queue
#define ub upper_bound
#define lb lower_bound
template<typename T, typename U> bool emin(T &a, const U &b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool emax(T &a, const U &b){ return b > a ? a = b, true : false; }
typedef uint64_t hash_t;
// vectors
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vpii vector<pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define vppipi vector<pair<int, pair<int, int>>>
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>
#define vpll vector<pair<ll, ll>>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define vs vector<string>
#define sz(x) (int)x.size()
#define rz resize
#define all(x) x.begin(), x.end()
#define vc vector<char>
#define vvc vector<vc>
// pairs
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define f first
#define s second
// sets
#define si set<int>
#define sl set<ll>
#define ss set<string>
#define in insert
template <class T> using iset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// maps
#define mii map<int, int>
#define mll map<ll, ll>
// loops
#define FR(x, z, y) for (int x = z; x < y; x++)
#define FRE(x, z, y) FR(x, z, y + 1)
#define F(x, y) FR(x, 0, y)
#define FE(x, y) F(x, y + 1)
#define A(x, y) for(auto &x : y)
vl a;
ll n, k;
pll plop(ll j) {
vvpll dp(n, vpll(2));
dp[0][0] = {0, 0};
dp[0][1] = {a[0] - j, 1};
FR(i, 1, n){
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = max(mp(dp[i - 1][1].f + a[i], dp[i - 1][1].s), mp(dp[i - 1][0].f + a[i] - j, dp[i - 1][0].s + 1));
}
return max(dp[n - 1][0], dp[n - 1][1]);
}
int main(){
cin >> n >> k;
a = vl(n); A(u, a) cin >> u;
ll l = 0, r = (ll) 1e16;
while(l < r) {
ll m = (l + r + 1) / 2;
if(plop(m).s < k) r = m - 1;
else l = m;
}
cout << plop(l).f + l * k;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
864 ms |
25200 KB |
Output is correct |
2 |
Correct |
929 ms |
25508 KB |
Output is correct |
3 |
Correct |
941 ms |
25984 KB |
Output is correct |
4 |
Correct |
870 ms |
26608 KB |
Output is correct |
5 |
Correct |
809 ms |
26248 KB |
Output is correct |
6 |
Correct |
794 ms |
25820 KB |
Output is correct |
7 |
Correct |
805 ms |
26032 KB |
Output is correct |
8 |
Correct |
861 ms |
26848 KB |
Output is correct |
9 |
Correct |
829 ms |
26152 KB |
Output is correct |
10 |
Correct |
824 ms |
26436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
797 ms |
24264 KB |
Output is correct |
2 |
Correct |
822 ms |
24972 KB |
Output is correct |
3 |
Correct |
850 ms |
23680 KB |
Output is correct |
4 |
Correct |
791 ms |
23812 KB |
Output is correct |
5 |
Correct |
816 ms |
23288 KB |
Output is correct |
6 |
Correct |
837 ms |
23332 KB |
Output is correct |
7 |
Correct |
796 ms |
23888 KB |
Output is correct |
8 |
Correct |
871 ms |
23792 KB |
Output is correct |
9 |
Correct |
884 ms |
25976 KB |
Output is correct |
10 |
Correct |
799 ms |
24924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
871 ms |
23700 KB |
Output is correct |
2 |
Correct |
932 ms |
26380 KB |
Output is correct |
3 |
Correct |
902 ms |
26644 KB |
Output is correct |
4 |
Correct |
985 ms |
26384 KB |
Output is correct |
5 |
Correct |
950 ms |
26680 KB |
Output is correct |
6 |
Correct |
834 ms |
27032 KB |
Output is correct |
7 |
Correct |
888 ms |
27088 KB |
Output is correct |
8 |
Correct |
912 ms |
26636 KB |
Output is correct |
9 |
Correct |
919 ms |
26980 KB |
Output is correct |
10 |
Correct |
886 ms |
26960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 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 |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
456 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
456 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
4 ms |
584 KB |
Output is correct |
22 |
Correct |
4 ms |
348 KB |
Output is correct |
23 |
Correct |
4 ms |
348 KB |
Output is correct |
24 |
Correct |
4 ms |
348 KB |
Output is correct |
25 |
Correct |
4 ms |
344 KB |
Output is correct |
26 |
Correct |
5 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
348 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
4 ms |
348 KB |
Output is correct |
30 |
Correct |
4 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
864 ms |
25200 KB |
Output is correct |
2 |
Correct |
929 ms |
25508 KB |
Output is correct |
3 |
Correct |
941 ms |
25984 KB |
Output is correct |
4 |
Correct |
870 ms |
26608 KB |
Output is correct |
5 |
Correct |
809 ms |
26248 KB |
Output is correct |
6 |
Correct |
794 ms |
25820 KB |
Output is correct |
7 |
Correct |
805 ms |
26032 KB |
Output is correct |
8 |
Correct |
861 ms |
26848 KB |
Output is correct |
9 |
Correct |
829 ms |
26152 KB |
Output is correct |
10 |
Correct |
824 ms |
26436 KB |
Output is correct |
11 |
Correct |
797 ms |
24264 KB |
Output is correct |
12 |
Correct |
822 ms |
24972 KB |
Output is correct |
13 |
Correct |
850 ms |
23680 KB |
Output is correct |
14 |
Correct |
791 ms |
23812 KB |
Output is correct |
15 |
Correct |
816 ms |
23288 KB |
Output is correct |
16 |
Correct |
837 ms |
23332 KB |
Output is correct |
17 |
Correct |
796 ms |
23888 KB |
Output is correct |
18 |
Correct |
871 ms |
23792 KB |
Output is correct |
19 |
Correct |
884 ms |
25976 KB |
Output is correct |
20 |
Correct |
799 ms |
24924 KB |
Output is correct |
21 |
Correct |
871 ms |
23700 KB |
Output is correct |
22 |
Correct |
932 ms |
26380 KB |
Output is correct |
23 |
Correct |
902 ms |
26644 KB |
Output is correct |
24 |
Correct |
985 ms |
26384 KB |
Output is correct |
25 |
Correct |
950 ms |
26680 KB |
Output is correct |
26 |
Correct |
834 ms |
27032 KB |
Output is correct |
27 |
Correct |
888 ms |
27088 KB |
Output is correct |
28 |
Correct |
912 ms |
26636 KB |
Output is correct |
29 |
Correct |
919 ms |
26980 KB |
Output is correct |
30 |
Correct |
886 ms |
26960 KB |
Output is correct |
31 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
344 KB |
Output is correct |
45 |
Correct |
1 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
456 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
4 ms |
584 KB |
Output is correct |
52 |
Correct |
4 ms |
348 KB |
Output is correct |
53 |
Correct |
4 ms |
348 KB |
Output is correct |
54 |
Correct |
4 ms |
348 KB |
Output is correct |
55 |
Correct |
4 ms |
344 KB |
Output is correct |
56 |
Correct |
5 ms |
348 KB |
Output is correct |
57 |
Correct |
4 ms |
348 KB |
Output is correct |
58 |
Correct |
4 ms |
348 KB |
Output is correct |
59 |
Correct |
4 ms |
348 KB |
Output is correct |
60 |
Correct |
4 ms |
348 KB |
Output is correct |
61 |
Correct |
847 ms |
26496 KB |
Output is correct |
62 |
Correct |
946 ms |
26992 KB |
Output is correct |
63 |
Correct |
871 ms |
26340 KB |
Output is correct |
64 |
Correct |
893 ms |
26812 KB |
Output is correct |
65 |
Correct |
888 ms |
26860 KB |
Output is correct |
66 |
Correct |
897 ms |
26736 KB |
Output is correct |
67 |
Correct |
869 ms |
26312 KB |
Output is correct |
68 |
Correct |
878 ms |
26876 KB |
Output is correct |
69 |
Correct |
901 ms |
26540 KB |
Output is correct |
70 |
Correct |
849 ms |
26272 KB |
Output is correct |