Submission #463627

# Submission time Handle Problem Language Result Execution time Memory
463627 2021-08-11T11:47:32 Z NintsiChkhaidze Stove (JOI18_stove) C++14
100 / 100
26 ms 3240 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pi pair<int,int>
#define s second
#define f first
#define int ll
using namespace std;

const int N = 100005;
int a[N];
vector <int> v;

signed main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n,k;
    cin>>n>>k;
    
    for (int i = 1; i <= n; i++)
        cin>>a[i];
    
    if (k == n){
        cout<<n;
        return 0;
    }
    
    sort(a + 1,a + n + 1);
    int res= a[n] + 1 - a[1];
    
    for (int i = 2; i <= n; i++)
        v.pb(a[i] - a[i - 1] - 1);
    
    sort(v.begin(),v.end());
    for (int i = v.size() - 1; i >= v.size() - k + 1; i--)
        res -= v[i];
    cout<<res;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:34:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
   34 |     for (int i = v.size() - 1; i >= v.size() - k + 1; i--)
      |                                ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 24 ms 3152 KB Output is correct
17 Correct 25 ms 3148 KB Output is correct
18 Correct 25 ms 3208 KB Output is correct
19 Correct 24 ms 3148 KB Output is correct
20 Correct 24 ms 3148 KB Output is correct
21 Correct 26 ms 3232 KB Output is correct
22 Correct 24 ms 3152 KB Output is correct
23 Correct 25 ms 3240 KB Output is correct
24 Correct 24 ms 3148 KB Output is correct