# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143792 | WhipppedCream | Stove (JOI18_stove) | C++17 | 31 ms | 2404 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>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
int main()
{
int n, k;
scanf("%d %d", &n, &k);
vector<int> arr(n);
for(int i = 0; i< n; i++) scanf("%d", &arr[i]);
vector<int> gap;
for(int i = 0; i+1< n; i++) gap.pb(arr[i+1]-arr[i]-1);
sort(gap.begin(), gap.end());
reverse(gap.begin(), gap.end());
int res = arr[n-1]-arr[0]+1;
for(int i = 0; i< k-1; i++) res -= gap[i];
printf("%d\n", res);
}
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... |