Submission #516298

# Submission time Handle Problem Language Result Execution time Memory
516298 2022-01-21T04:10:43 Z Jomnoi Stove (JOI18_stove) C++17
0 / 100
0 ms 204 KB
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;

const int N = 1e5 + 10;

int t[N];

int main() {
    int n, k;
    scanf(" %d %d", &n, &k);
    k = n - k;
    for(int i = 1; i <= n; i++) {
        scanf(" %d", &t[i]);
    }

    if(n == k) {
        printf("%d", n);
        return 0;
    }
    
    priority_queue <int, vector <int>, greater <int>> pq;
    for(int i = 2; i <= n; i++) {
        pq.emplace(t[i] - t[i - 1] + 1);
    }

    int ans = n - k - 1;
    while(!pq.empty() and k--) {
        ans += pq.top();
        pq.pop();
    }
    printf("%d", ans);
    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf(" %d %d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
stove.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf(" %d", &t[i]);
      |         ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -