답안 #754616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
754616 2023-06-08T07:02:56 Z Bula Stove (JOI18_stove) C++14
100 / 100
52 ms 2232 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int ll
 
const ll mod=1e9+7;
 
main(){
 
    int tt=1;//cin>>tt;
    while(tt--){
    	int n,k;
    	cin>>n>>k;
    	vector<int> v(n),diff;
    	
    	for(int i=0;i<n;i++){
    		cin>>v[i];
		}
		
		for(int i=1;i<n;i++){
			diff.pb(v[i]-v[i-1]);
		}
		
		sort(rall(diff));
		int N=diff.size(),t=0;
		for(int i=0;i<min(N,k-1);i++){
			t+=diff[i];
		}
		if(k==n) cout<<n<<endl;
		else cout<<(v[n-1]-v[0])-t+k<<endl;
		//for(int i=0;i<n;i++) cout<<p[i]<<" ";
	}
 
}
 
 

Compilation message

stove.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   12 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 47 ms 2220 KB Output is correct
17 Correct 43 ms 2120 KB Output is correct
18 Correct 42 ms 2116 KB Output is correct
19 Correct 42 ms 2224 KB Output is correct
20 Correct 44 ms 2232 KB Output is correct
21 Correct 42 ms 2232 KB Output is correct
22 Correct 52 ms 2116 KB Output is correct
23 Correct 43 ms 2116 KB Output is correct
24 Correct 44 ms 2232 KB Output is correct