Submission #867971

#TimeUsernameProblemLanguageResultExecution timeMemory
867971VN_AnhTuanStove (JOI18_stove)C++14
100 / 100
21 ms2408 KiB
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define bit(X,i) ((X>>i)&1)
#define fori(i,d,c) for(int i = d; i <= c; ++ i)
#define ford(i,d,c) for(int i = d; i >= c; -- i)
#define all(V) V.begin(), V.end()
#define RRH(V) V.resize(unique(all(V))-V.begin())
#define debug(x) { cerr << #x << " = "; cerr << (x) << '\n'; }
#define open(Task) if (fopen(Task".inp", "r")) {freopen(Task".inp", "r", stdin);freopen(Task".out", "w", stdout);}
 
using namespace std;
using ll = long long;
using ld = long double;
 
const int maxn = 1e5 + 5;
const int maxm = 1e5 + 5;
const int base = 101;
 
int n, m, a[maxn];
 
void read() {
    cin >> n >> m; m --;
    fori(i,1,n) cin >> a[i];
}
 
void solve() {
    priority_queue<int> pq;
    fori(i,2,n) {
        pq.push(max(0,a[i] - (a[i-1] + 1)));
    }
    int res = a[n] - a[1] + 1;
    while(m --> 0 && !pq.empty()) {
        res -= pq.top();
        pq.pop();
    }
    cout << res;
}
 
int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    open("stove");
    read();
    solve();
    return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:14:56: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define open(Task) if (fopen(Task".inp", "r")) {freopen(Task".inp", "r", stdin);freopen(Task".out", "w", stdout);}
      |                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:46:5: note: in expansion of macro 'open'
   46 |     open("stove");
      |     ^~~~
stove.cpp:14:88: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | #define open(Task) if (fopen(Task".inp", "r")) {freopen(Task".inp", "r", stdin);freopen(Task".out", "w", stdout);}
      |                                                                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:46:5: note: in expansion of macro 'open'
   46 |     open("stove");
      |     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...