Submission #559630

# Submission time Handle Problem Language Result Execution time Memory
559630 2022-05-10T10:34:29 Z joshjms Stove (JOI18_stove) C++17
100 / 100
25 ms 3028 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define debug(x) cout << #x << " => " << x << "\n";

const long long mod = 1e9 + 7;

int n, k, a[100005], ans;
vector <int> v;

void solve () {
    cin >> n >> k;
    k--;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        if(i > 1) v.pb(a[i] - a[i - 1] - 1);
    }
    ans = a[n] - a[1] + 1;
    sort(v.begin(), v.end(), greater<int>());
    for(int i = 0; i < k && i < v.size(); i++)
        ans -= v[i];
    cout << ans << "\n";
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve ();
}

Compilation message

stove.cpp: In function 'void solve()':
stove.cpp:25:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for(int i = 0; i < k && i < v.size(); i++)
      |                             ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 17 ms 3028 KB Output is correct
17 Correct 17 ms 2904 KB Output is correct
18 Correct 18 ms 2896 KB Output is correct
19 Correct 18 ms 2892 KB Output is correct
20 Correct 20 ms 2980 KB Output is correct
21 Correct 25 ms 2984 KB Output is correct
22 Correct 18 ms 2900 KB Output is correct
23 Correct 19 ms 2980 KB Output is correct
24 Correct 18 ms 2904 KB Output is correct