Submission #485754

#TimeUsernameProblemLanguageResultExecution timeMemory
485754dongliu0426Stove (JOI18_stove)C++17
100 / 100
23 ms1656 KiB
#include <bits/stdc++.h>
using namespace std;

#define N	100000

int main() {
	int n, k, ans;
	static int tt[N];

	scanf("%d%d", &n, &k), k--;
	for (int i = 0; i < n; i++)
		scanf("%d", &tt[i]);
	ans = tt[n - 1] - tt[0] + 1;
	for (int i = 0; i < n; i++)
		tt[i] = tt[i + 1] - tt[i] - 1;
	sort(tt, tt + n - 1);
	for (int i = 0; i < k; i++)
		ans -= tt[n - 1 - i - 1];
	printf("%d\n", ans);
	return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%d%d", &n, &k), k--;
      |  ~~~~~^~~~~~~~~~~~~~~~
stove.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("%d", &tt[i]);
      |   ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...