Submission #648196

# Submission time Handle Problem Language Result Execution time Memory
648196 2022-10-05T16:43:58 Z jekabs Stove (JOI18_stove) C++14
Compilation error
0 ms 0 KB
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    int t[n];
    for(auto &x:t)
    {
        cin >> x;
    }
    sort(t, t + n);
    vector <int> atn;
    int ans = t[n-1] - t[0] + 1;
    for(int i = 0;i < n;i++)
    {
        atn.push_back(t[i] - t[i-1] - 1);
    }
    sort(atn.begin(),atn.end(), greater<int>());
    for(int i = 0;i < k - 1;i++)
    {
        ans-=atn[i];
    }
    cout << ans;

    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:14:5: error: 'vector' was not declared in this scope
   14 |     vector <int> atn;
      |     ^~~~~~
stove.cpp:3:1: note: 'std::vector' is defined in header '<vector>'; did you forget to '#include <vector>'?
    2 | #include <algorithm>
  +++ |+#include <vector>
    3 | using namespace std;
stove.cpp:14:13: error: expected primary-expression before 'int'
   14 |     vector <int> atn;
      |             ^~~
stove.cpp:18:9: error: 'atn' was not declared in this scope
   18 |         atn.push_back(t[i] - t[i-1] - 1);
      |         ^~~
stove.cpp:20:10: error: 'atn' was not declared in this scope
   20 |     sort(atn.begin(),atn.end(), greater<int>());
      |          ^~~