# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1004885 | MarwenElarbi | Stove (JOI18_stove) | C++17 | 0 ms | 344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ii pair<int,int>
const int nax=5e2+5;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int n,k;
cin>>n>>k;
int tab[n];
for (int i = 0; i < n; ++i)
{
cin>>tab[i];
}
vector<int> nabba;
for (int i = 1; i < n; ++i)
{
nabba.pb(tab[i]-tab[i-1]-1);
}
sort(nabba.begin(),nabba.end());
int sum=tab[n-1]+1-tab[0];
for (int i = nabba.size()-1; i >= (int)nabba.size()-k+1 ; --i)
{
sum-=nabba[i];
}
cout <<sum<<endl;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |