답안 #66722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66722 2018-08-12T07:30:12 Z hamzqq9 Stove (JOI18_stove) C++14
100 / 100
34 ms 1764 KB
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1000000000000000
#define MOD 1000000007
#define N 100005
#define MAX 10000006
#define LOG 22
using namespace std;

int n,k;
int a[N];
vector<int> e;

int main() {

//	freopen("input.txt","r",stdin);

	scanf("%d %d",&n,&k);

	for(int i=1;i<=n;i++) {

		scanf("%d",&a[i]);

	}

	sort(a+1,a+1+n);

	int comp=n;

	for(int i=1;i<n;i++) {

		e.pb(abs(a[i]-a[i+1]));

	}

	sort(all(e));

	int ans=n;

	int cur=0;

	while(comp>k) {

		comp--;

		ans+=e[cur]-1;

		cur++;

	}

	printf("%d\n",ans);

}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&k);
  ~~~~~^~~~~~~~~~~~~~~
stove.cpp:36:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&a[i]);
   ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 3 ms 516 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 3 ms 656 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 2 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 3 ms 516 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 3 ms 656 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 2 ms 656 KB Output is correct
10 Correct 3 ms 656 KB Output is correct
11 Correct 4 ms 656 KB Output is correct
12 Correct 3 ms 656 KB Output is correct
13 Correct 4 ms 656 KB Output is correct
14 Correct 4 ms 656 KB Output is correct
15 Correct 4 ms 656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 412 KB Output is correct
4 Correct 2 ms 496 KB Output is correct
5 Correct 3 ms 516 KB Output is correct
6 Correct 2 ms 656 KB Output is correct
7 Correct 3 ms 656 KB Output is correct
8 Correct 2 ms 656 KB Output is correct
9 Correct 2 ms 656 KB Output is correct
10 Correct 3 ms 656 KB Output is correct
11 Correct 4 ms 656 KB Output is correct
12 Correct 3 ms 656 KB Output is correct
13 Correct 4 ms 656 KB Output is correct
14 Correct 4 ms 656 KB Output is correct
15 Correct 4 ms 656 KB Output is correct
16 Correct 29 ms 1640 KB Output is correct
17 Correct 28 ms 1644 KB Output is correct
18 Correct 30 ms 1656 KB Output is correct
19 Correct 33 ms 1764 KB Output is correct
20 Correct 33 ms 1764 KB Output is correct
21 Correct 30 ms 1764 KB Output is correct
22 Correct 34 ms 1764 KB Output is correct
23 Correct 30 ms 1764 KB Output is correct
24 Correct 30 ms 1764 KB Output is correct