답안 #971847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971847 2024-04-29T11:41:58 Z Sunbae Stove (JOI18_stove) C++17
0 / 100
1 ms 348 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 = 1; 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);
      |                           ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -