Submission #648187

# Submission time Handle Problem Language Result Execution time Memory
648187 2022-10-05T16:34:50 Z matissh Stove (JOI18_stove) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll n,k;
    cin >> n >> k;
    ll a[n];
    for(ll i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    sort(a,a+n);
    ll ans=a[n-1];
    vector<ll> v;
    v.push_back(a[i]-1);
    for(ll i = 1;i < n;i++)
    {
        v.push_back(a[i]-a[i-1]-1);
    }
    sort(v.begin(),v.end());
    k--;
    for(ll i = v.size()-1;k!=0;i--)
    {
        ans-=v[i];
        k--;
    }
    cout << ans;
    return 0;
}

Compilation message

stove.cpp: In function 'int main()':
stove.cpp:17:19: error: 'i' was not declared in this scope
   17 |     v.push_back(a[i]-1);
      |                   ^