Submission #1049706

# Submission time Handle Problem Language Result Execution time Memory
1049706 2024-08-09T04:23:45 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
12 ms 1508 KB
#include <iostream>
#include <fstream>
#include <iomanip>
#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 <numeric>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <complex>
#include <climits>
#include <random>
using namespace std;

#define ll long long
#define pb push_back
#define ull unsigned long long
#define F first
#define S second
#define all(v) v.begin(), v.end() 
#define rall(x) x.rbegin(), (x).rend()

const ll mod = 1e9 + 7;
const int block = 450;
const ll LINF = 1e16;
const int INF = 1e8;

ll add(ll a, ll b){
    ll x = a + b;
    if(x < 0) x += mod;
    if(x >= mod) x -= mod;
    return x;
}

ll mul(ll a, ll b){
    return (a * b) % mod;
}

ll sub(ll x, ll y){
    return add(x, -y);
}   

ll binpow(ll a, ll b) {
    ll res = 1LL;
    while (b > 0) {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

int n, m;
int a[100005];

void solve(){
    cin >> n >> m;
    int ans = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    ans = (a[n] + 1) - a[1];
    vector<int> v;
    int prev = a[1] + 1;
    for(int i = 2; i <= n; i++){
        v.pb(-(a[i] - prev));
        prev = a[i] + 1;
    }
    sort(all(v));
    for(int i = 0; i < min((int) v.size(), (m - 1)); i++){
        int x = v[i];
        ans += x;
    }
    cout << ans;
}  
 
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    int xach = 1; 
    //cin >> xach;
    while(xach--) solve();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 12 ms 1508 KB Output is correct
17 Correct 12 ms 1504 KB Output is correct
18 Correct 12 ms 1504 KB Output is correct
19 Correct 12 ms 1504 KB Output is correct
20 Correct 12 ms 1504 KB Output is correct
21 Correct 11 ms 1504 KB Output is correct
22 Correct 12 ms 1492 KB Output is correct
23 Correct 12 ms 1504 KB Output is correct
24 Correct 12 ms 1504 KB Output is correct