답안 #647972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647972 2022-10-04T17:21:45 Z rohith_231 Stove (JOI18_stove) C++17
컴파일 오류
0 ms 0 KB
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n,k; cin>>n>>k;
  vector<int>arr(n); for(int i=0;i<n;i++) cin>>arr[i];
  vector<int>diff(n-1);
  for(int i=0;i<n-1;i++) {
    diff[i] = arr[i+1]-arr[i]-1;
  }
   sort(diff.begin(),diff.end(),greater<int>());
  int res = arr[n-1]+1-arr[0];
  for(int i=0;i<k-1;i++) res-=diff[i];
  cout<<res<<endl;
  
  return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:4:3: error: 'ios' has not been declared
    4 |   ios::sync_with_stdio(false);
      |   ^~~
stove.cpp:5:3: error: 'cin' was not declared in this scope
    5 |   cin.tie(NULL);
      |   ^~~
stove.cpp:1:1: note: 'std::cin' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
  +++ |+#include <iostream>
    1 | using namespace std;
stove.cpp:5:11: error: 'NULL' was not declared in this scope
    5 |   cin.tie(NULL);
      |           ^~~~
stove.cpp:1:1: note: 'NULL' is defined in header '<cstddef>'; did you forget to '#include <cstddef>'?
  +++ |+#include <cstddef>
    1 | using namespace std;
stove.cpp:7:3: error: 'vector' was not declared in this scope
    7 |   vector<int>arr(n); for(int i=0;i<n;i++) cin>>arr[i];
      |   ^~~~~~
stove.cpp:1:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
  +++ |+#include <vector>
    1 | using namespace std;
stove.cpp:7:10: error: expected primary-expression before 'int'
    7 |   vector<int>arr(n); for(int i=0;i<n;i++) cin>>arr[i];
      |          ^~~
stove.cpp:7:48: error: 'arr' was not declared in this scope
    7 |   vector<int>arr(n); for(int i=0;i<n;i++) cin>>arr[i];
      |                                                ^~~
stove.cpp:8:10: error: expected primary-expression before 'int'
    8 |   vector<int>diff(n-1);
      |          ^~~
stove.cpp:10:5: error: 'diff' was not declared in this scope
   10 |     diff[i] = arr[i+1]-arr[i]-1;
      |     ^~~~
stove.cpp:10:15: error: 'arr' was not declared in this scope
   10 |     diff[i] = arr[i+1]-arr[i]-1;
      |               ^~~
stove.cpp:12:9: error: 'diff' was not declared in this scope
   12 |    sort(diff.begin(),diff.end(),greater<int>());
      |         ^~~~
stove.cpp:12:33: error: 'greater' was not declared in this scope
   12 |    sort(diff.begin(),diff.end(),greater<int>());
      |                                 ^~~~~~~
stove.cpp:12:41: error: expected primary-expression before 'int'
   12 |    sort(diff.begin(),diff.end(),greater<int>());
      |                                         ^~~
stove.cpp:12:4: error: 'sort' was not declared in this scope; did you mean 'short'?
   12 |    sort(diff.begin(),diff.end(),greater<int>());
      |    ^~~~
      |    short
stove.cpp:13:13: error: 'arr' was not declared in this scope
   13 |   int res = arr[n-1]+1-arr[0];
      |             ^~~
stove.cpp:15:3: error: 'cout' was not declared in this scope
   15 |   cout<<res<<endl;
      |   ^~~~
stove.cpp:15:3: note: 'std::cout' is defined in header '<iostream>'; did you forget to '#include <iostream>'?
stove.cpp:15:14: error: 'endl' was not declared in this scope
   15 |   cout<<res<<endl;
      |              ^~~~
stove.cpp:1:1: note: 'std::endl' is defined in header '<ostream>'; did you forget to '#include <ostream>'?
  +++ |+#include <ostream>
    1 | using namespace std;