Submission #498909

# Submission time Handle Problem Language Result Execution time Memory
498909 2021-12-26T14:49:31 Z aSSSd Stove (JOI18_stove) C++14
100 / 100
74 ms 2292 KB
#pragma GCC optimize("O2,unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r)
{
    return l+rng()%(r-l+1);
}
#define fasty ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define forinc(x,a,b) for(int x=a;x<=b;x++)
#define fordec(x,a,b) for(int x=a;x>=b;x--)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define getbit(x,i) ((x>>(i))&1)
#define batbit(x,i) (x|(1ll<<(i)))
#define tatbit(x,i) (x&~(1<<(i)))
#define all(a) a.begin() , a.end()
int n,k;
int a[1000000+100];


main()
{
    int t;
    t=1;
    //cin >> t;
    while(t--)
    {
        priority_queue<int, vector<int> > h;
        cin >> n >> k;
        forinc(i,1,n) cin >> a[i];
        long long  ans = a[n] - a[1] + 1;
        forinc(i,1,n-1) h.push(a[i+1] - a[i]);
        forinc(i,1,k-1)
        {
            ans -= h.top() ;
            ans+=1;
            h.pop();
        }
        cout << ans << "\n";
    }
}

Compilation message

stove.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 2 ms 316 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 2 ms 312 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 2 ms 316 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 3 ms 332 KB Output is correct
13 Correct 2 ms 312 KB Output is correct
14 Correct 2 ms 336 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 47 ms 2260 KB Output is correct
17 Correct 74 ms 2232 KB Output is correct
18 Correct 45 ms 2268 KB Output is correct
19 Correct 44 ms 2240 KB Output is correct
20 Correct 47 ms 2292 KB Output is correct
21 Correct 51 ms 2240 KB Output is correct
22 Correct 50 ms 2224 KB Output is correct
23 Correct 62 ms 2236 KB Output is correct
24 Correct 67 ms 2292 KB Output is correct