Submission #1143387

#TimeUsernameProblemLanguageResultExecution timeMemory
1143387duyngadoctonStove (JOI18_stove)C++17
100 / 100
20 ms1480 KiB
#include<bits/stdc++.h>

using namespace std;

#define task "stove"
#define pb push_back
#define ll long long

const int MAX = (int) 1e5;

int n, k;
int t[MAX + 5];

int main() {
    if(fopen(task".inp","r")) {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }
    ios::sync_with_stdio(0);
    cin.tie(NULL);cout.tie(NULL);
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
        cin >> t[i];
    vector<int> lst;
    for(int i = 2; i <= n; ++i) {
        lst.pb(t[i] - t[i - 1]);
    }
    sort(lst.begin(), lst.end());
    reverse(lst.begin(), lst.end());
    ll ds = 0;
    for(int i = 1; i < k; ++i) ds += lst[i - 1];
    cout << t[n] - ds - t[1] + k;
}

Compilation message (stderr)

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