Submission #1100319

#TimeUsernameProblemLanguageResultExecution timeMemory
1100319anhphantStove (JOI18_stove)C++14
100 / 100
18 ms3540 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N, K, T[100007];

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0); cerr.tie(0);
	if (fopen("FILE.INP", "r")) {
		freopen("FILE.INP", "r", stdin);
		freopen("FILE.OUT", "w", stdout);
	}

	cin >> N >> K;
	for(int i = 1; i <= N; ++i) cin >> T[i];

	ll sum = T[N] + 1 - T[1];
	vector<ll> v;
	for(int i = 2; i <= N; ++i) {
		v.push_back(T[i] - T[i - 1] - 1);
		//cerr << i << " " << T[i] - T[i - 1] - 1 << '\n';
	}

	sort(v.begin(), v.end(), greater<ll>());
	for(int i = 0; i < K - 1; ++i) {
		sum -= v[i];
	}

	cout << sum;
}

Compilation message (stderr)

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