답안 #541960

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541960 2022-03-24T21:49:09 Z DemonLord154 Stove (JOI18_stove) C++14
컴파일 오류
0 ms 0 KB
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int n,k;
  cin>>n>>k;
  vector<int> vec(n);
  for (int i=0;i<n;i++){
    cin>>vec[i];
  }
	sort(vec.begin(),vec.end());
  vector<int> intervals;
  for (int i=1;i<n;i++){
    if (vec[i]-vec[i-1]>0){
      intervals.push_back(vec[i]-vec[i-1]);
    }
  }
  sort(intervals.begin(),intervals.end());
  if (intervals.size()<k){
    cout<<n<<"\n";
  } else{
    int ans=0;
    for (int i=0;i<n-k-1;i++){
      ans+=intervals[i];
    }
    cout<<(n+ans)<<"\n";
  }
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:11:2: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   11 |  sort(vec.begin(),vec.end());
      |  ^~~~
      |  qsort
stove.cpp:19:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   19 |   if (intervals.size()<k){
      |       ~~~~~~~~~~~~~~~~^~