Submission #494816

#TimeUsernameProblemLanguageResultExecution timeMemory
494816aris12345678Stove (JOI18_stove)C++14
100 / 100
27 ms2244 KiB
#include <bits/stdc++.h>
using namespace std;

const int mxN = 100005;
int a[mxN];

int main() {
    int n, k;
    scanf("%d %d", &n, &k);
    for(int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    vector<int> diff;
    for(int i = 1; i < n; i++)
        diff.push_back(a[i]-a[i-1]-1);
    sort(diff.begin(), diff.end(), greater<int>());
    int ans = a[n-1]-a[0]+1;
    for(int i = 0; i < k-1; i++)
        ans -= diff[i];
    printf("%d\n", ans);
    return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...