Submission #708454

# Submission time Handle Problem Language Result Execution time Memory
708454 2023-03-11T19:25:40 Z deme_bz Stove (JOI18_stove) C++14
100 / 100
87 ms 2240 KB
#pragma GCC diagnostic warning "-std=c++11"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define eb emplace_back
#define sz(x) (int)x.size()
using namespace std;
const int N=2e5+5;
 
ll A[N];
void test_case(){
	//cout << INT_MAX+1 << endl; 
	int n,k;
	cin >> n >> k;
	
	for(int i=1;i<=n;i++){
		cin >> A[i];
	}
	vector<ll> v;
	for(int i=2;i<=n;i++){
		v.pb(A[i]-A[i-1]-1);
	}
		sort(all(v));
	
	ll answer=A[n]-A[1]+1;
	//cout << v.size()-1 << endl;
	if(v.size()>0){
		assert(k-1<=v.size());
		for(int i=v.size()-1;i>=0 && i>=v.size()+1-k;i--){
			answer-=v[i];
		}
	}
	
	cout << answer << endl;
}




main(){
	//ios_base::sync_with_stdio(false);
    int T = 1;
    //cin >> T;
    while(T--){
        test_case();
    }
}

Compilation message

stove.cpp:1:32: warning: '-std=c++11' is not an option that controls warnings [-Wpragmas]
    1 | #pragma GCC diagnostic warning "-std=c++11"
      |                                ^~~~~~~~~~~~
In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from stove.cpp:2:
stove.cpp: In function 'void test_case()':
stove.cpp:31:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   assert(k-1<=v.size());
      |          ~~~^~~~~~~~~~
stove.cpp:32:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |   for(int i=v.size()-1;i>=0 && i>=v.size()+1-k;i--){
      |                                ~^~~~~~~~~~~~~~
stove.cpp: At global scope:
stove.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 2 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 216 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 3 ms 340 KB Output is correct
15 Correct 2 ms 316 KB Output is correct
16 Correct 43 ms 2132 KB Output is correct
17 Correct 45 ms 2240 KB Output is correct
18 Correct 51 ms 2212 KB Output is correct
19 Correct 46 ms 2188 KB Output is correct
20 Correct 49 ms 2184 KB Output is correct
21 Correct 87 ms 2120 KB Output is correct
22 Correct 45 ms 2180 KB Output is correct
23 Correct 65 ms 2228 KB Output is correct
24 Correct 58 ms 2200 KB Output is correct