Submission #251922

#TimeUsernameProblemLanguageResultExecution timeMemory
251922paradoxStove (JOI18_stove)C++17
100 / 100
28 ms2292 KiB
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
using namespace std;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define vi vector<int>
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
 
typedef long long ll;
typedef short inth;
 
const int N = 1e5;
const int M = N + 7;
const int MOD = 1e9 + 7;
const ll INF = 1e16 + 17;

int a[M];

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

    vi dif;

    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        if (i > 1)
            dif.pb(a[i] - a[i - 1] - 1);
    }

    sort(all(dif));
    reverse(all(dif));

    int ans = a[n] - a[1] + 1;

    for (int i = 0; i < k - 1; ++i)
        ans -= dif[i];
    
    printf("%d\n", ans);
    return 0;
}

Compilation message (stderr)

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