Submission #335880

#TimeUsernameProblemLanguageResultExecution timeMemory
335880Killer2501Stove (JOI18_stove)C++14
100 / 100
33 ms7916 KiB
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pb push_back
#define pii pair<ll ,pll>
#define task "C"

using namespace std;
const int N = 2e5+5;
const int M = 4e6+5;
const int mod = 1e9+7;
ll n, t, m, k, a[N], ans, tong, h[N], u, v;

string s;
bool ok;
vector<ll> adj[N], kq;
vector<pll> res;
struct dang
{
    ll x, y, h;
}e[N], f[N];
bool cmp(const dang& u, const dang& v)
{
    return u.h < v.h;
}
void sol()
{
    cin >> n >> m;
    for(int i = 1; i <= n; i ++)cin >> a[i];
    sort(a+1, a+1+n);
    priority_queue<ll> pq;
    for(int i = 2; i <= n; i ++)pq.push(a[i]-a[i-1]-1);
    ans = a[n] - a[1] + 1;
    while(m > 1)
    {
        ans -= pq.top();
        pq.pop();
        --m;
    }
    cout << ans;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if(fopen(task".inp", "r"))
    {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    sol();
}

Compilation message (stderr)

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