# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
998442 |
2024-06-14T01:53:47 Z |
HUECTRUM |
Feast (NOI19_feast) |
C++14 |
|
217 ms |
12220 KB |
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_set>
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bitset>
#include <sstream>
#include <ext/rope>
#include <ctime>
#include <random>
#include <cstdlib>
#include <complex>
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
/* clang-format off */
/* TYPES */
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define vpii vector<pair<int, int>>
#define vpii vector<pair<int, int>>
#define vvpii vector<vector<pair<int, int>>>
#define vpll vector<pair<long long, long long>>
#define vvpll vector<vector<pair<long long, long long>>>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define mii map<int, int>
#define si set<int>
#define sc set<char>
/* FUNCTIONS */
#define feach(el, v) for(auto &el: v)
#define rep(i, n) for(int i=0;i<n;i++)
#define reprv(i, n) for(int i=n-1;i>=0;i--)
#define reps(i, s, e) for(int i=s;i<e;i++)
#define reprve(i, e, s) for(int i=e-1;i>=s;i--)
#define repe(x, y) for (auto &x: y)
#define repe2(x, a, y) for (auto &[x,a]: y)
typedef tree<int, null_type, less_equal<>, rb_tree_tag, tree_order_statistics_node_update> oSet;
const ll mod = 1e9 + 7;
template<ll mod = 1000000007>
struct ModInt {
ll p;
ModInt() : p(0) {}
ModInt(ll x) { p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod; }
ModInt &operator+=(const ModInt &y) {
p = p + *y - ((p + *y) >= mod ? mod : 0);
return *this;
}
ModInt &operator-=(const ModInt &y) {
p = p - *y + (p - *y < 0 ? mod : 0);
return *this;
}
ModInt &operator*=(const ModInt &y) {
p = (p * *y) % mod;
return *this;
}
ModInt &operator%=(const ModInt &y) {
if (y)p %= *y;
return *this;
}
ModInt operator+(const ModInt &y) const {
ModInt x = *this;
return x += y;
}
ModInt operator-(const ModInt &y) const {
ModInt x = *this;
return x -= y;
}
ModInt operator*(const ModInt &y) const {
ModInt x = *this;
return x *= y;
}
ModInt operator%(const ModInt &y) const {
ModInt x = *this;
return x %= y;
}
ModInt binpow(const ModInt &y, ll pow) const {
pow %= mod - 1;
ModInt res = 1, a = y;
while (pow) {
if (pow & 1) res *= a;
a *= a, pow >>= 1;
}
return res;
}
ModInt inv() const { return binpow(*this, mod - 2); }
ModInt &operator/=(const ModInt &y) {
p = (p * y.inv().p) % mod;
return *this;
}
ModInt operator/(const ModInt &y) const {
ModInt x = *this;
return x /= y;
}
friend istream &operator>>(istream &is, ModInt &a) {
int v;
is >> v;
a = ModInt(v);
return is;
}
friend ostream &operator<<(ostream &os, const ModInt &a) { return os << a.p; }
ModInt &operator++() {
p = (p + 1) % mod;
return *this;
}
ModInt &operator--() {
p = (p - 1 + mod) % mod;
return *this;
}
bool operator==(const ModInt &y) const { return p == *y; }
bool operator!=(const ModInt &y) const { return p != *y; }
const ll &operator*() const { return p; }
ll &operator*() { return p; }
};
using Mint = ModInt<>;
#define vmint vector<Mint>
#pragma GCC target("popcnt")
//////////////////////////////////////////////////////////////////////////
int n;
vll v;
pll solve(ll lambda) {
pair<ll, ll> dp[n][2];
dp[0][0] = {0, 0}, dp[0][1] = {v[0] - lambda, 1};
reps(i, 1, n) {
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
dp[i][1] = max(
make_pair(dp[i - 1][0].first + v[i] - lambda, dp[i - 1][0].second + 1),
make_pair(dp[i - 1][1].first + v[i], dp[i - 1][1].second)
);
}
return max(dp[n - 1][0], dp[n - 1][1]);
}
int main() {
ll k; cin >> n >> k;
v = vll(n); rep(i, n) cin >> v[i];
ll l = 0, r = 1e18;
while (r > l) {
ll mid = (l + r + 1) / 2;
pll sol = solve(mid);
if (sol.second >= k) l = mid;
else r = mid - 1;
}
pll sL = solve(l);
cout << sL.first + k * l;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
11668 KB |
Output is correct |
2 |
Correct |
121 ms |
11960 KB |
Output is correct |
3 |
Correct |
117 ms |
12116 KB |
Output is correct |
4 |
Correct |
117 ms |
11856 KB |
Output is correct |
5 |
Correct |
114 ms |
11952 KB |
Output is correct |
6 |
Correct |
116 ms |
11600 KB |
Output is correct |
7 |
Correct |
113 ms |
11600 KB |
Output is correct |
8 |
Correct |
115 ms |
11960 KB |
Output is correct |
9 |
Correct |
114 ms |
11600 KB |
Output is correct |
10 |
Correct |
125 ms |
11860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
11856 KB |
Output is correct |
2 |
Correct |
87 ms |
11996 KB |
Output is correct |
3 |
Correct |
110 ms |
11856 KB |
Output is correct |
4 |
Correct |
83 ms |
11956 KB |
Output is correct |
5 |
Correct |
115 ms |
11604 KB |
Output is correct |
6 |
Correct |
83 ms |
11600 KB |
Output is correct |
7 |
Correct |
86 ms |
11988 KB |
Output is correct |
8 |
Correct |
129 ms |
11856 KB |
Output is correct |
9 |
Correct |
137 ms |
11604 KB |
Output is correct |
10 |
Correct |
84 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
11856 KB |
Output is correct |
2 |
Correct |
151 ms |
11860 KB |
Output is correct |
3 |
Correct |
147 ms |
11856 KB |
Output is correct |
4 |
Correct |
147 ms |
11856 KB |
Output is correct |
5 |
Correct |
144 ms |
11968 KB |
Output is correct |
6 |
Correct |
150 ms |
11856 KB |
Output is correct |
7 |
Correct |
148 ms |
11992 KB |
Output is correct |
8 |
Correct |
158 ms |
12220 KB |
Output is correct |
9 |
Correct |
166 ms |
11996 KB |
Output is correct |
10 |
Correct |
149 ms |
11856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 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 |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 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 |
348 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 |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
11668 KB |
Output is correct |
2 |
Correct |
121 ms |
11960 KB |
Output is correct |
3 |
Correct |
117 ms |
12116 KB |
Output is correct |
4 |
Correct |
117 ms |
11856 KB |
Output is correct |
5 |
Correct |
114 ms |
11952 KB |
Output is correct |
6 |
Correct |
116 ms |
11600 KB |
Output is correct |
7 |
Correct |
113 ms |
11600 KB |
Output is correct |
8 |
Correct |
115 ms |
11960 KB |
Output is correct |
9 |
Correct |
114 ms |
11600 KB |
Output is correct |
10 |
Correct |
125 ms |
11860 KB |
Output is correct |
11 |
Correct |
86 ms |
11856 KB |
Output is correct |
12 |
Correct |
87 ms |
11996 KB |
Output is correct |
13 |
Correct |
110 ms |
11856 KB |
Output is correct |
14 |
Correct |
83 ms |
11956 KB |
Output is correct |
15 |
Correct |
115 ms |
11604 KB |
Output is correct |
16 |
Correct |
83 ms |
11600 KB |
Output is correct |
17 |
Correct |
86 ms |
11988 KB |
Output is correct |
18 |
Correct |
129 ms |
11856 KB |
Output is correct |
19 |
Correct |
137 ms |
11604 KB |
Output is correct |
20 |
Correct |
84 ms |
11988 KB |
Output is correct |
21 |
Correct |
149 ms |
11856 KB |
Output is correct |
22 |
Correct |
151 ms |
11860 KB |
Output is correct |
23 |
Correct |
147 ms |
11856 KB |
Output is correct |
24 |
Correct |
147 ms |
11856 KB |
Output is correct |
25 |
Correct |
144 ms |
11968 KB |
Output is correct |
26 |
Correct |
150 ms |
11856 KB |
Output is correct |
27 |
Correct |
148 ms |
11992 KB |
Output is correct |
28 |
Correct |
158 ms |
12220 KB |
Output is correct |
29 |
Correct |
166 ms |
11996 KB |
Output is correct |
30 |
Correct |
149 ms |
11856 KB |
Output is correct |
31 |
Correct |
0 ms |
600 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 |
348 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 |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
0 ms |
348 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 |
344 KB |
Output is correct |
54 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
348 KB |
Output is correct |
61 |
Correct |
172 ms |
11856 KB |
Output is correct |
62 |
Correct |
217 ms |
12112 KB |
Output is correct |
63 |
Correct |
164 ms |
11824 KB |
Output is correct |
64 |
Correct |
177 ms |
12112 KB |
Output is correct |
65 |
Correct |
182 ms |
11856 KB |
Output is correct |
66 |
Correct |
185 ms |
11860 KB |
Output is correct |
67 |
Correct |
180 ms |
11852 KB |
Output is correct |
68 |
Correct |
151 ms |
11984 KB |
Output is correct |
69 |
Correct |
156 ms |
11680 KB |
Output is correct |
70 |
Correct |
144 ms |
11656 KB |
Output is correct |