답안 #548870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548870 2022-04-14T15:29:20 Z DemonLord154 Stove (JOI18_stove) C++14
컴파일 오류
0 ms 0 KB
#include<iostream>
using namespace std;

int solve(int n, vector<int> & times, int k){
 	vector<int> gaps(n-1);
  for (int i=0;i<n-1;i++){
    gaps[i]=times[i+1]-times[i]-1;
  }
  sort(gaps.begin(),gaps.end(),greater<int>());
  int answer= times[n-1]-times[0]+1
  for (int i=0;i<k-1;i++){
    answer-=gaps[i];
  }
  return answer;
}
int main(){
  int n,k;
  cin>>n>>k;
  vector <int> times(n);
  for (int i=0;i<n;i++){
    cin>>times[i];
  }
  cout<<solve(n,times,k)<<"\n";
  return 0;
}

Compilation message

stove.cpp:4:18: error: 'vector' has not been declared
    4 | int solve(int n, vector<int> & times, int k){
      |                  ^~~~~~
stove.cpp:4:24: error: expected ',' or '...' before '<' token
    4 | int solve(int n, vector<int> & times, int k){
      |                        ^
stove.cpp: In function 'int solve(int, int)':
stove.cpp:5:3: error: 'vector' was not declared in this scope
    5 |   vector<int> gaps(n-1);
      |   ^~~~~~
stove.cpp:2:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    1 | #include<iostream>
  +++ |+#include <vector>
    2 | using namespace std;
stove.cpp:5:10: error: expected primary-expression before 'int'
    5 |   vector<int> gaps(n-1);
      |          ^~~
stove.cpp:7:5: error: 'gaps' was not declared in this scope
    7 |     gaps[i]=times[i+1]-times[i]-1;
      |     ^~~~
stove.cpp:7:13: error: 'times' was not declared in this scope; did you mean 'time'?
    7 |     gaps[i]=times[i+1]-times[i]-1;
      |             ^~~~~
      |             time
stove.cpp:9:8: error: 'gaps' was not declared in this scope
    9 |   sort(gaps.begin(),gaps.end(),greater<int>());
      |        ^~~~
stove.cpp:9:3: error: 'sort' was not declared in this scope; did you mean 'qsort'?
    9 |   sort(gaps.begin(),gaps.end(),greater<int>());
      |   ^~~~
      |   qsort
stove.cpp:10:15: error: 'times' was not declared in this scope; did you mean 'time'?
   10 |   int answer= times[n-1]-times[0]+1
      |               ^~~~~
      |               time
stove.cpp:11:16: error: 'i' was not declared in this scope
   11 |   for (int i=0;i<k-1;i++){
      |                ^
stove.cpp:11:18: error: 'k' was not declared in this scope
   11 |   for (int i=0;i<k-1;i++){
      |                  ^
stove.cpp: In function 'int main()':
stove.cpp:19:3: error: 'vector' was not declared in this scope
   19 |   vector <int> times(n);
      |   ^~~~~~
stove.cpp:19:3: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
stove.cpp:19:11: error: expected primary-expression before 'int'
   19 |   vector <int> times(n);
      |           ^~~
stove.cpp:21:10: error: 'times' was not declared in this scope; did you mean 'time'?
   21 |     cin>>times[i];
      |          ^~~~~
      |          time
stove.cpp:23:17: error: 'times' was not declared in this scope; did you mean 'time'?
   23 |   cout<<solve(n,times,k)<<"\n";
      |                 ^~~~~
      |                 time