Submission #849676

# Submission time Handle Problem Language Result Execution time Memory
849676 2023-09-15T07:55:04 Z chilengaming Stove (JOI18_stove) C++17
100 / 100
15 ms 2420 KB
#include<bits/stdc++.h>
using namespace std;

//Num
#define int long long 
#define ld long double

//Vector or String
#define all(v) v.begin(), v.end()
#define sor(v) sort(all(v))
#define sz(v) (long long) v.size()
#define remu(v) v.erase(unique(all(v)), end(v))
#define pb push_back
#define eb emplace_back

//Pair Map
#define fi first 
#define se second
#define pii pair<int, int>
#define mii map<int, int>
#define mib map<int, bool>

//Loop
#define fou(i, a, b) for(int i = a; i <= b; i++)
#define fod(i, a, b) for(int i = a; i >= b; i--)

//Gragh
const int dx[8] = {0, 0, 1, -1, -1, -1, 1, 1};
const int dy[8] = {1, -1, 0, 0, -1, 1, -1, 1};

//Some Func
template <class T> bool ckmin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}
template <class T> bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}
string its(int n) {
    stringstream ss;
    ss << n;
    string s;
    ss >> s;
    return s;
}
int sti(string s) {
    stringstream ss;
    ss << s;
    int n;
    ss >> n;
    return n;
}

//Input Output 
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TASK "fi"
#define el '\n'

//Mod MaxN 
const int MOD = 1e9 + 7;
const int MAX = 2e5 + 1;
const int INF = 1e18;
const ld PI = acos((ld)-1);
int ar[100001];

void solve() {
    int n, k;
    cin >> n >> k;
    fou(i, 1,n ) {
        cin >> ar[i];
    }
    int ans = ar[n] - ar[1] + 1;
    vector<int> v;
    fou(i, 2, n) {
        v.pb(ar[i] - ar[i - 1] - 1);
    }
    sort(v.begin(), v.end(), greater<int>());
    fou(i ,0, k-2) {
        ans -= v[i];
    }
    cout << ans;
}

signed main() {
    FIO;
    //freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
    int Q = 1;
    //cin >> Q;
    while(Q--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 360 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 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 344 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 360 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 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 344 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 1 ms 480 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 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 360 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 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 344 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 1 ms 480 KB Output is correct
12 Correct 1 ms 512 KB Output is correct
13 Correct 1 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 14 ms 2268 KB Output is correct
17 Correct 15 ms 2412 KB Output is correct
18 Correct 14 ms 2268 KB Output is correct
19 Correct 15 ms 2268 KB Output is correct
20 Correct 15 ms 2420 KB Output is correct
21 Correct 14 ms 2268 KB Output is correct
22 Correct 14 ms 2268 KB Output is correct
23 Correct 14 ms 2268 KB Output is correct
24 Correct 15 ms 2268 KB Output is correct