Submission #548871

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

stove.cpp: In function 'int solve(int, std::vector<int>&, int)':
stove.cpp:10:3: error: 'sort' was not declared in this scope; did you mean 'qsort'?
   10 |   sort(gaps.begin(),gaps.end(),greater<int>());
      |   ^~~~
      |   qsort
stove.cpp:12:3: error: expected ',' or ';' before 'for'
   12 |   for (int i=0;i<k-1;i++){
      |   ^~~
stove.cpp:12:16: error: 'i' was not declared in this scope
   12 |   for (int i=0;i<k-1;i++){
      |                ^