Submission #754581

# Submission time Handle Problem Language Result Execution time Memory
754581 2023-06-08T06:34:29 Z pera Stove (JOI18_stove) C++17
100 / 100
57 ms 2236 KB
#include<bits/stdc++.h>
using namespace std;

#define int ll
#define ll long long

const int mod = 1e9 + 7;


main(){
    int n , k;cin >> n >> k;
    vector<int> a(n + 1) , v;
    for(int i = 1;i <= n;i ++){
        cin >> a[i];
    }
    sort(a.begin() + 1 , a.end());
    int s = a[n] - a[1];
    for(int i = 2;i <= n;i ++){
        v.push_back(a[i] - a[i - 1]);
    }
    sort(v.rbegin() , v.rend());
    for(int i = 0;i < min((int)v.size() , k - 1);i ++){
        s -= v[i];
    }
    cout << (k == n ? n : s + k) << endl;
}

Compilation message

stove.cpp:10:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   10 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 57 ms 2228 KB Output is correct
17 Correct 48 ms 2232 KB Output is correct
18 Correct 48 ms 2236 KB Output is correct
19 Correct 46 ms 2220 KB Output is correct
20 Correct 45 ms 2116 KB Output is correct
21 Correct 46 ms 2224 KB Output is correct
22 Correct 46 ms 2232 KB Output is correct
23 Correct 47 ms 2116 KB Output is correct
24 Correct 50 ms 2116 KB Output is correct