Submission #556119

# Submission time Handle Problem Language Result Execution time Memory
556119 2022-05-02T11:25:03 Z HeatDroppa Stove (JOI18_stove) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim=1e5+4;
const ll inf=1e18;
//ll dp_new[lim];
//ll dp_old[lim];
int t[lim];
int n,k;
/*void solve(int l,int r,int optl,int optr)
{
    if(l>r) return ;
    int med=(l+r)>>1;
    pair<ll,int> bst={inf,-1};
    for(int i=optl;i<=min(med,optr);++i)
        bst=min(bst,{dp_old[i-1]+t[med]-t[i]+1,i});
    dp_new[med]=bst.first;
    solve(l,med-1,optl,bst.second);
    solve(med+1,r,bst.second,optr);
}*/
void solution()
{
    ll ans=t[n]-t[1]+1;
    vector<ll> raz;
    for(int i=2;i<=n; ++i)
        raz.push_back(t[i]-t[i-1]-1);
    sort(raz.begin(),raz.end());
    for(int i=1;i<=k-1;++i)
        ans-=raz[i];
    cout<<ans<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;++i)
        cin>>t[i];//,
        //dp_old[i]=t[i]-t[1]+1;
    /*for(int i=2;i<=k;++i)
        solve(i,n,i,n),
        swap(dp_old,dp_new);
    cout<<dp_old[n]<<'\n';*/
    solution();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -