Submission #62224

#TimeUsernameProblemLanguageResultExecution timeMemory
62224kingpig9Stove (JOI18_stove)C++11
100 / 100
57 ms10620 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAXN = 1e5 + 10; #define debug(...) fprintf(stderr, __VA_ARGS__) #define fi first #define se second #define all(v) (v).begin(), (v).end() #define fillchar(a, s) memset((a), (s), sizeof(a)) int N, K; int A[MAXN]; int main() { scanf("%d %d", &N, &K); for (int i = 0; i < N; i++) { scanf("%d", &A[i]); } sort(A, A + N); int ans = A[N - 1] - A[0] + 1; priority_queue<int> pq; for (int i = 0; i < N; i++) { pq.push(A[i + 1] - A[i] - 1); } //K - 1 times at most for (int i = 1; i < K; i++) { if (pq.empty()) { break; } ans -= pq.top(); pq.pop(); } printf("%d\n", ans); }

Compilation message (stderr)

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