Submission #42266

#TimeUsernameProblemLanguageResultExecution timeMemory
42266RezwanArefin01Stove (JOI18_stove)C++14
100 / 100
44 ms1528 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii; 

const int maxn = 1e5 + 10;
int a[maxn], n, k;

int main(int argc, char const *argv[]) {
#ifdef LOCAL_TESTING
	freopen("in", "r", stdin);
#endif
	scanf("%d %d", &n, &k);
	vector<int> v; 
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		if(i > 1) v.push_back(a[i - 1] - a[i]);
	}
	sort(v.begin(), v.end());
	int ans = a[n] - a[1] + k;
	for(int i = 0; i < k - 1; i++) ans += v[i];
 	cout << ans << endl;
}

Compilation message (stderr)

stove.cpp: In function 'int main(int, const char**)':
stove.cpp:14:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
                        ^
stove.cpp:17:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...