답안 #559738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
559738 2022-05-10T13:22:25 Z Stavab Stove (JOI18_stove) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    freopen("stove.in", "r", stdin);

    int n, k;
    scanf("%d %d", &n, &k);
    k--;

    priority_queue<long long> pq;

    long long start, input, prev;
    scanf("%lld", &start);
    prev = start;
    for(int i = 1; i < n; i++)
    {
        scanf("%lld", &input);
        pq.push(input - prev - 1);
        prev = input;
    }

    long long answer = input - start + 1;
    while(!pq.empty())
    {
        if(k > 0)
        {
            answer -= pq.top();
            pq.pop();
            k--;
        }
        else break;
    }

    printf("%lld\n", answer);

    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:7:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    7 |     freopen("stove.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |     scanf("%lld", &start);
      |     ~~~~~^~~~~~~~~~~~~~~~
stove.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         scanf("%lld", &input);
      |         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -