Submission #831320

# Submission time Handle Problem Language Result Execution time Memory
831320 2023-08-20T04:37:15 Z manhtuan22007 Stove (JOI18_stove) C++14
0 / 100
1 ms 464 KB
#include <bits/stdc++.h>
#define int long long
#define ll long long
using namespace std;

const int maxn = 1e5 + 10;

int n , k , a[maxn];

int32_t main()
{
	cin.tie(0)->sync_with_stdio(0);
	if(fopen(".inp" , "r")){
		freopen(".inp" , "r" , stdin);
		freopen(".out" , "w" , stdout);
	}
	cin >> n >> k;
	for(int i = 1 ; i <= n ; i ++) cin >> a[i];
	vector<int> v;
	for(int i = 2 ; i <= n ; i ++){
		v.push_back(a[i] - a[i - 1] - 1);
	}
	sort(v.begin() , v.end());
	int res = a[n] - a[1] + 1;
	for(int i = n - 1 ; i >= n - k ; i --){
		res -= v[i];
	}
	cout << res;
}	

Compilation message

stove.cpp: In function 'int32_t main()':
stove.cpp:14:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |   freopen(".inp" , "r" , stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:15:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   freopen(".out" , "w" , stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Runtime error 1 ms 464 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Runtime error 1 ms 464 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Runtime error 1 ms 464 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -