Submission #559739

#TimeUsernameProblemLanguageResultExecution timeMemory
559739StavabStove (JOI18_stove)C++14
0 / 100
1 ms212 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    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 (stderr)

stove.cpp: In function 'int main()':
stove.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     scanf("%d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~
stove.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     scanf("%lld", &start);
      |     ~~~~~^~~~~~~~~~~~~~~~
stove.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%lld", &input);
      |         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...