Submission #976091

#TimeUsernameProblemLanguageResultExecution timeMemory
976091woodStove (JOI18_stove)C++17
100 / 100
20 ms2492 KiB
#include <bits/stdc++.h>  
using namespace std;
 
typedef long long ll;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vi vector<int>
#define vp32 vector<p32>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MOD %1000000007
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


int main()
{
    fast_cin();
    #ifndef ONLINE_JUDGE
        #ifdef _WIN32
            freopen("input.in", "r", stdin);
            freopen("input.out", "w", stdout);
        #endif
    #endif
    int n,k; cin>>n>>k;
    k--;
    int arr [n];
    for(int & sub : arr){
        cin>>sub;
    }
    sort(arr,arr+n);
    priority_queue<int> q;
    for (size_t i = 1; i < n; i++)
        q.push(arr[i]-arr[i-1]-1);
    int res = arr[n-1]-arr[0]+1;
    while(k--){
        res-=q.top();
        q.pop();
    }
    cout<<res<<'\n';
    return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:39:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |     for (size_t i = 1; i < n; i++)
      |                        ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...