Submission #541959

#TimeUsernameProblemLanguageResultExecution timeMemory
541959DemonLord154Stove (JOI18_stove)C++14
Compilation error
0 ms0 KiB
#include<iostream> #include<vector> 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 (stderr)

stove.cpp: In function 'int main()':
stove.cpp:6:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
    6 |   cin>>n>>k;
      |   ^~~
      |   std::cin
In file included from stove.cpp:1:
/usr/include/c++/10/iostream:60:18: note: 'std::cin' declared here
   60 |   extern istream cin;  /// Linked to standard input
      |                  ^~~
stove.cpp:7:3: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
    7 |   vector<int> vec(n);
      |   ^~~~~~
      |   std::vector
In file included from /usr/include/c++/10/vector:67,
                 from stove.cpp:2:
/usr/include/c++/10/bits/stl_vector.h:389:11: note: 'std::vector' declared here
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
stove.cpp:7:10: error: expected primary-expression before 'int'
    7 |   vector<int> vec(n);
      |          ^~~
stove.cpp:9:10: error: 'vec' was not declared in this scope
    9 |     cin>>vec[i];
      |          ^~~
stove.cpp:11:7: error: 'vec' was not declared in this scope
   11 |  sort(vec.begin(),vec.end());
      |       ^~~
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:12:10: error: expected primary-expression before 'int'
   12 |   vector<int> intervals;
      |          ^~~
stove.cpp:15:7: error: 'intervals' was not declared in this scope
   15 |       intervals.push_back(vec[i]-vec[i-1]);
      |       ^~~~~~~~~
stove.cpp:18:8: error: 'intervals' was not declared in this scope
   18 |   sort(intervals.begin(),intervals.end());
      |        ^~~~~~~~~
stove.cpp:20:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   20 |     cout<<n<<"\n";
      |     ^~~~
      |     std::cout
In file included from stove.cpp:1:
/usr/include/c++/10/iostream:61:18: note: 'std::cout' declared here
   61 |   extern ostream cout;  /// Linked to standard output
      |                  ^~~~
stove.cpp:26:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   26 |     cout<<(n+ans)<<"\n";
      |     ^~~~
      |     std::cout
In file included from stove.cpp:1:
/usr/include/c++/10/iostream:61:18: note: 'std::cout' declared here
   61 |   extern ostream cout;  /// Linked to standard output
      |                  ^~~~