Submission #627135

# Submission time Handle Problem Language Result Execution time Memory
627135 2022-08-12T08:59:33 Z boris_mihov Stove (JOI18_stove) C++17
100 / 100
22 ms 1680 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
#include <cmath>

typedef long long llong;
const int MAXN = 100000 + 10;
const int MAXLOG = 17;
const int INF  = 2e9;

int a[MAXN], n, k;
void solve()
{
    int diff = a[n] - a[1] + 1;
    for (int i = n ; i >= 2 ; --i)
    {
        a[i] -= a[i-1];
        a[i]--;
    }

    int sum = 0;
    std::sort(a+2, a+1+n); --k;
    for (int i = n ; i >= n - k + 1 ; --i)
    {
        sum += a[i];
    }

    std::cout << diff - sum << '\n';
}

void read()
{
    std::cin >> n >> k;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }
}

void fastIO()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}

int main()
{
    fastIO();
    read();
    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 328 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 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 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 16 ms 1620 KB Output is correct
17 Correct 17 ms 1620 KB Output is correct
18 Correct 16 ms 1620 KB Output is correct
19 Correct 17 ms 1620 KB Output is correct
20 Correct 19 ms 1680 KB Output is correct
21 Correct 18 ms 1664 KB Output is correct
22 Correct 17 ms 1592 KB Output is correct
23 Correct 16 ms 1620 KB Output is correct
24 Correct 22 ms 1596 KB Output is correct