Submission #1005470

#TimeUsernameProblemLanguageResultExecution timeMemory
1005470jamjanekStove (JOI18_stove)C++14
100 / 100
21 ms2388 KiB
#include<bits/stdc++.h>
using namespace std;
int a[100010], b[100010];
int main()
{
  int n, k, i;
  scanf("%d%d", &n, &k);
  for(i=0;i<n;i++)
    scanf("%d", &a[i]);
  sort(a, a+n);
  for(i=0;i<n-1;i++)b[i] = -(a[i+1]-a[i]-1);
  sort(b, b+n-1);
  int res = a[n-1]-a[0]+1;
  for(i=0;i<k-1;i++)res+=b[i];
  printf("%d\n", res);
}

Compilation message (stderr)

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