Submission #212707

#TimeUsernameProblemLanguageResultExecution timeMemory
212707KoalaMuchStove (JOI18_stove)C++14
100 / 100
31 ms2120 KiB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int a[N];
int b[N];
int main()
{
    int n,k,ans;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++)   scanf("%d",&a[i]);
    ans = a[n]+1-a[1];
    for(int i=1;i<n;i++)    b[i] = a[i]+1-a[i+1];
    sort(b+1,b+n);
    for(int i=1;i<k;i++)    ans+=b[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]
     scanf("%d %d",&n,&k);
     ~~~~~^~~~~~~~~~~~~~~
stove.cpp:10:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++)   scanf("%d",&a[i]);
                             ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...