Submission #971846

# Submission time Handle Problem Language Result Execution time Memory
971846 2024-04-29T11:40:39 Z Sunbae Stove (JOI18_stove) C++17
0 / 100
1 ms 440 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
int a[N];
signed main(){
	int n, k; scanf("%d %d", &n, &k);
	for(int i = 0; i<n; ++i) scanf("%d", a+i);
	sort(a, a+n);
	using T = pair<ll,int>;
	priority_queue<T, vector<T>, greater<T>> pq;
	for(int i = 0; i<n-1; ++i) pq.emplace(a[i]-a[i+1], i);
	ll ans = k + (a[n-1] - a[0]);
	for(int i = 0; i<k-1; ++i) ans += pq.top().first; pq.pop();
	printf("%lld", ans);
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:14:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   14 |  for(int i = 0; i<k-1; ++i) ans += pq.top().first; pq.pop();
      |  ^~~
stove.cpp:14:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   14 |  for(int i = 0; i<k-1; ++i) ans += pq.top().first; pq.pop();
      |                                                    ^~
stove.cpp:7:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |  int n, k; scanf("%d %d", &n, &k);
      |            ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:8:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |  for(int i = 0; i<n; ++i) scanf("%d", a+i);
      |                           ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 440 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 440 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 0 ms 440 KB Output isn't correct
4 Halted 0 ms 0 KB -