Submission #1151031

#TimeUsernameProblemLanguageResultExecution timeMemory
1151031thiendeptraiStove (JOI18_stove)C++20
100 / 100
16 ms2244 KiB
#include <bits/stdc++.h>
#define task "stove"
#define int long long
#define ii std::pair<int, int>
#define iii std::pair<ii, int>
#define fi first
#define se second
#define pb push_back
#define ins insert

const int maxn = 1e5;

int n, k;
int a[maxn + 7], f[maxn + 7];

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

    if (std::fopen(task ".inp", "r"))
    {
        std::freopen(task ".inp", "r", stdin);
        std::freopen(task ".out", "w", stdout);
    }

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

    int ans = a[n] - a[1] + 1;
    std::vector<int> v;
    for (int i = 1; i < n; i++)
    {
        v.pb(a[i + 1] - a[i] - 1);
    }
    std::sort(v.begin(), v.end(), std::greater<int>());
    for (int i = 0; i < k - 1; i++)
    {
        ans -= v[i];
    }
    std::cout << ans;

    return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:24:21: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         std::freopen(task ".inp", "r", stdin);
      |         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:25:21: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         std::freopen(task ".out", "w", stdout);
      |         ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...