# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1109860 |
2024-11-07T23:16:00 Z |
aguss |
Stove (JOI18_stove) |
C++14 |
|
27 ms |
5832 KB |
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#define INF LLONG_MAX
#define MOD 1000000007
#define endl "\n"
#define sp " "
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f1(i, x) for(auto &i : x)
#define f2(i, x, j) for(ll i = j; i < x; i++)
#define raya() cout << endl << "====================================" << endl
#define dbg(x) cerr << #x << ": " << x << endl;
using namespace std;
using ll = long long;
void solve(){
ll n, k;
cin >> n >> k;
vector<ll> arr(n), sel;
f1(i, arr){
cin >> i;
}
vector<pair<ll, ll>> dur;
f2(i, n - 1, 0){
dur.push_back({arr[i + 1] - arr[i] - 1, i});
}
sort(rall(dur));
f2(i, k - 1, 0){
sel.push_back(dur[i].second);
}
sort(all(sel));
if(!sel.size()){
cout << arr[n - 1] + 1 - arr[0];
return;
}
ll start = 0, j = 0, ans = 0;
f2(i, n - 1, 0){
if(j < sel.size()){
if(i == sel[j]){
j++;
ans += arr[i] + 1 - arr[start];
start = i + 1;
}
}
}
ans += arr[n - 1] + 1 - arr[start];
cout << ans;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
Compilation message
stove.cpp: In function 'void solve()':
stove.cpp:44:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | if(j < sel.size()){
| ~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
516 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
592 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
1 ms |
516 KB |
Output is correct |
13 |
Correct |
2 ms |
592 KB |
Output is correct |
14 |
Correct |
2 ms |
592 KB |
Output is correct |
15 |
Correct |
1 ms |
592 KB |
Output is correct |
16 |
Correct |
21 ms |
5312 KB |
Output is correct |
17 |
Correct |
21 ms |
5324 KB |
Output is correct |
18 |
Correct |
21 ms |
5324 KB |
Output is correct |
19 |
Correct |
20 ms |
5336 KB |
Output is correct |
20 |
Correct |
23 ms |
5496 KB |
Output is correct |
21 |
Correct |
25 ms |
5824 KB |
Output is correct |
22 |
Correct |
27 ms |
5832 KB |
Output is correct |
23 |
Correct |
26 ms |
5832 KB |
Output is correct |
24 |
Correct |
25 ms |
5832 KB |
Output is correct |