# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1088114 |
2024-09-14T02:10:09 Z |
LucasLe |
Stove (JOI18_stove) |
C++17 |
|
15 ms |
3360 KB |
#include <bits/stdc++.h>
#define int long long
#define moony long long
#define pii pair<int, int>
#define fi first
#define se second
#define ld long double
#define vi vector<int>
#define vii vector<vector<int>>
#define all(v) (v).begin(), (v).end()
#define rep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define per(i, b, a) for (int i = (b), _a = (a); i >= _a; --i)
using namespace std;
const int MOD = 1e9 + 7;
int add(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return a;
}
int mul(int a, int b) {
(a *= b) %= MOD;
return a;
}
int ceil(int x, int y) {
return (x + y - 1) / y;
}
int bin_pow(int x, int y) {
int res=1;
while(y){if(y&1)res=res*x%MOD;x=x*x%MOD;y>>=1;}
return res;
}
const int INF = 1e17;
const int maxn = 1e6 + 5;
int n, k;
int t[maxn + 5];
void solve(int tc) {
// (t[j] - t[1]) + (t[k] - t[j + 1]) + (t[z] - t[k + 1]) + (t[n] - t[z + 1])
// = (t[n] - t[1]) + (t[j] - t[j + 1]) + (t[k] - t[k + 1]) + (t[z] - t[z + 1])
cin >> n >> k;
for (int i = 1; i <= n; ++i) cin >> t[i];
int ans = t[n] - t[1] + 1;
if (n == 2) {
if (k == 2) ans = min(ans, 2ll);
cout << ans;
return;
}
vector<int> vec;
for (int i = 1; i + 1 <= n; ++i)
vec.push_back(t[i] - t[i + 1] + 1);
sort(all(vec));
for (int i = 0; i < min(k - 1, (int)vec.size()); ++i)
ans += vec[i];
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int tc = 1;
//cin >> tc;
for (int i = 1; i <= tc; ++i) {
solve(i);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
392 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 |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
392 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 |
344 KB |
Output is correct |
10 |
Correct |
1 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
392 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 |
344 KB |
Output is correct |
10 |
Correct |
1 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 |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
14 ms |
3280 KB |
Output is correct |
17 |
Correct |
13 ms |
3288 KB |
Output is correct |
18 |
Correct |
13 ms |
3344 KB |
Output is correct |
19 |
Correct |
13 ms |
3288 KB |
Output is correct |
20 |
Correct |
13 ms |
3292 KB |
Output is correct |
21 |
Correct |
13 ms |
3288 KB |
Output is correct |
22 |
Correct |
15 ms |
3360 KB |
Output is correct |
23 |
Correct |
13 ms |
3292 KB |
Output is correct |
24 |
Correct |
13 ms |
3320 KB |
Output is correct |