Submission #208736

#TimeUsernameProblemLanguageResultExecution timeMemory
208736tushar_2658Stove (JOI18_stove)C++14
100 / 100
34 ms3312 KiB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 100005;
using ll = long long;

ll a[maxn];

int main(int argc, char const *argv[])
{
//  freopen("in.txt", "r", stdin);
  int n, k;
  scanf("%d %d", &n, &k);
  for(int i = 1; i <= n; i++){
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + n + 1); 
  vector<ll> v;
  for(int i = 2; i <= n; i++){
    v.push_back(a[i] - a[i - 1]);
  }
  sort(v.begin(), v.end(), greater<ll>());
  ll ans = 0;
  int cnt = 0;
  for(int i = 0; i < (int)v.size(); i++){
    if(i < k - 1){
      ans++;
    }else {
      ans += v[i];
    }
  }
  cout << ans + 1 << endl;

  return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main(int, const char**)':
stove.cpp:24:7: warning: unused variable 'cnt' [-Wunused-variable]
   int cnt = 0;
       ^~~
stove.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   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]
     scanf("%lld", &a[i]);
     ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...