Submission #1241896

#TimeUsernameProblemLanguageResultExecution timeMemory
1241896khanhttStove (JOI18_stove)C++20
100 / 100
11 ms1480 KiB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n,k,A[100005];
vector<int> gap;
main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    for (int i=1; i<=n; i++) cin >> A[i];
    if (k>=n){
        cout << n;
    }
    else{
        for (int i=2; i<=n; i++){
            gap.push_back(A[i]-A[i-1]);
        }
        sort(gap.begin(),gap.end(),greater<>());
        int cost=A[n]-A[1]+1;
        for (int i=0; i<k-1; i++){
            cost-=(gap[i]-1);
        }
        cout << cost;
    }
}

Compilation message (stderr)

stove.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...