Submission #1308802

#TimeUsernameProblemLanguageResultExecution timeMemory
1308802liptonekStove (JOI18_stove)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n,k;
    cin>>n>>k;

    vector<long long> t(n);

    for(int i=0; i<n; i++)
    {
        cin>>t[i];
    }

    vector<long long> gaps;

    if(n>1)
    {
        gaps.reserve(n-1)

        for(int i=0; i<n-1; i++)
        {
            long long len=t[i+1]-t[i]-1;

            gaps.push_back(len);
        }
    }

    long long total=(t[n-1]+1)-t[0];

    sort(gaps.begin(), garps.end()m greater<long long>());

    int cuts=k-1;

    for(int i=0; i<gaps.size(); i++)
    {
        if(i<cuts)
        {
            total-=gaps[i];
        }
        else
        {
            break;
        }
    }

    cout<<total<<endl;

    return 0;
}

Compilation message (stderr)

stove.cpp: In function 'int main()':
stove.cpp:23:26: error: expected ';' before 'for'
   23 |         gaps.reserve(n-1)
      |                          ^
      |                          ;
   24 | 
   25 |         for(int i=0; i<n-1; i++)
      |         ~~~               
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:26: error: the value of 'n' is not usable in a constant expression
   25 |         for(int i=0; i<n-1; i++)
      |                          ^
stove.cpp:9:9: note: 'int n' is not const
    9 |     int n,k;
      |         ^
stove.cpp:25:22: error: 'i' was not declared in this scope
   25 |         for(int i=0; i<n-1; i++)
      |                      ^
stove.cpp:35:24: error: 'garps' was not declared in this scope; did you mean 'gaps'?
   35 |     sort(gaps.begin(), garps.end()m greater<long long>());
      |                        ^~~~~
      |                        gaps