Submission #528477

#TimeUsernameProblemLanguageResultExecution timeMemory
528477georgerapeanuStove (JOI18_stove)C++11
100 / 100
32 ms2276 KiB
#include <bits/stdc++.h>

using namespace std;

int main(){
  
  int n, k;
  scanf("%d %d", &n, &k);

  vector<int> v(n, 0);

  sort(v.begin(), v.end());

  for(auto &it:v){
    scanf("%d", &it);
  }
  vector<int> stuff;
  for(int i = 1;i < n;i++){
    stuff.push_back(v[i] - v[i - 1] - 1);
  }

  int ans = v.back() - v[0] + 1;
  sort(stuff.begin(), stuff.end());
  reverse(stuff.begin(), stuff.end());

  for(int i = 0;i < k - 1;i++){
    ans -= max(0, stuff[i]);
  }

  printf("%d", ans);

  return 0;
}

Compilation message (stderr)

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