Submission #50503

#TimeUsernameProblemLanguageResultExecution timeMemory
50503gnoorStove (JOI18_stove)C++17
100 / 100
33 ms10524 KiB
#include <cstdio> #include <algorithm> #include <vector> using namespace std; int tbl[100100]; int main() { int n,k; scanf("%d%d",&n,&k); vector<int> dif; int a; int b; for (int i=0;i<n;i++) { scanf("%d",&tbl[i]); if (i) { dif.push_back(tbl[i]-tbl[i-1]-1); } if (!i) a=tbl[i]; b=tbl[i]; } sort(dif.begin(),dif.end()); //for (int i=0;i<n-1;i++) { //printf("%d\n",dif[i]); //} int ans=b-a; //printf("%d %d\n",a,b); for (int i=0;i<k-1;i++) { //printf("i %d\n",i); //printf("%d\n",dif[n-i-2]); ans-=dif[n-i-2]; } printf("%d\n",ans+1); return 0; }

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:11:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~
stove.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&tbl[i]);
   ~~~~~^~~~~~~~~~~~~~
stove.cpp:29:6: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
  int ans=b-a;
      ^~~
stove.cpp:29:6: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...