Submission #334195

#TimeUsernameProblemLanguageResultExecution timeMemory
334195shahriarkhanStove (JOI18_stove)C++14
100 / 100
25 ms2408 KiB
#include<bits/stdc++.h> using namespace std ; const int INF = 1e9 ; int main() { int n , k ; scanf("%d%d",&n,&k) ; int a[n+1] ; for(int i = 1 ; i <= n ; ++i) scanf("%d",&a[i]) ; sort(a+1,a+n+1) ; vector<int> v ; int tot = a[n] - a[1] + 1 ; for(int i = 1 ; i < n ; ++i) { v.push_back(a[i]-a[i+1]+1) ; } sort(v.begin(),v.end()) ; for(int i = 0 ; i < (k-1) ; ++i) tot += v[i] ; printf("%d\n",tot) ; 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:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |     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...