Submission #1100319

# Submission time Handle Problem Language Result Execution time Memory
1100319 2024-10-13T13:39:34 Z anhphant Stove (JOI18_stove) C++14
100 / 100
18 ms 3540 KB
#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

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 time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 2 ms 524 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 508 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 504 KB Output is correct
14 Correct 2 ms 524 KB Output is correct
15 Correct 1 ms 508 KB Output is correct
16 Correct 15 ms 3284 KB Output is correct
17 Correct 15 ms 3284 KB Output is correct
18 Correct 15 ms 3284 KB Output is correct
19 Correct 18 ms 3392 KB Output is correct
20 Correct 15 ms 3284 KB Output is correct
21 Correct 16 ms 3284 KB Output is correct
22 Correct 16 ms 3284 KB Output is correct
23 Correct 15 ms 3284 KB Output is correct
24 Correct 16 ms 3540 KB Output is correct