답안 #1017864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017864 2024-07-09T10:50:11 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
45 ms 3136 KB
#include <bits/stdc++.h>
#define int long long
#define Aiko ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define pb push_back
using namespace std;
const int  INF=1e18;
	
signed main(){
    int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
    cin>>n>>k;
    int a[n+1];
    int ans[n+1];
    int sum[n+1];
    for(i=1;i<=n;i++){
    	cin>>a[i];
	}
	if(k==1)cout<<a[n]+1-a[1];
	else if(n<=k)cout<<n;
	else{
		sum[0]=0;
		vector<int>v;
		for(i=1;i<n;i++){
			v.pb(a[i+1]-a[i]-1);
		}
		int ans11=a[n]-a[1]+1;
		sort(v.begin(),v.end());
		reverse(v.begin(),v.end());
		for(i=0;i<k-1;i++){
			ans11-=v[i];
		}
		cout<<ans11;
	}
		
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:9:18: warning: unused variable 'j' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                  ^
stove.cpp:9:21: warning: unused variable 'ans1' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                     ^~~~
stove.cpp:9:29: warning: unused variable 'mn' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                             ^~
stove.cpp:9:35: warning: unused variable 'mx' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                                   ^~
stove.cpp:9:44: warning: unused variable 'ans3' [-Wunused-variable]
    9 |     int n, i, k, j, ans1=0, mn=0, mx=-INF, ans3=0;
      |                                            ^~~~
stove.cpp:12:9: warning: unused variable 'ans' [-Wunused-variable]
   12 |     int ans[n+1];
      |         ^~~
stove.cpp:13:9: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
   13 |     int sum[n+1];
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 30 ms 3020 KB Output is correct
17 Correct 45 ms 3016 KB Output is correct
18 Correct 30 ms 3128 KB Output is correct
19 Correct 33 ms 3016 KB Output is correct
20 Correct 30 ms 3020 KB Output is correct
21 Correct 36 ms 3120 KB Output is correct
22 Correct 30 ms 3136 KB Output is correct
23 Correct 30 ms 3028 KB Output is correct
24 Correct 45 ms 3128 KB Output is correct