Submission #163424

#TimeUsernameProblemLanguageResultExecution timeMemory
163424iefnah06Stove (JOI18_stove)C++11
100 / 100
58 ms2420 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5; int N, K; int T[MAXN]; int main() { scanf("%d %d", &N, &K); for (int i = 0; i < N; i++) { scanf("%d", &T[i]); } vector<int> gaps; for (int i = 0; i < N - 1; i++) { gaps.push_back(T[i + 1] - T[i] - 1); } nth_element(gaps.begin(), gaps.begin() + K - 1, gaps.end(), greater<int>()); int ans = T[N - 1] - T[0] + 1; for (int i = 0; i < K - 1; i++) { ans -= gaps[i]; } printf("%d\n", ans); return 0; }

Compilation message (stderr)

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