Submission #966454

# Submission time Handle Problem Language Result Execution time Memory
966454 2024-04-19T22:54:17 Z Aliyyiakbar Stove (JOI18_stove) C++17
0 / 100
0 ms 348 KB
#include <iostream>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/hash_policy.hpp>

#define int long long
#define $AzH_TxdmN$ ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")

#define pb push_back
#define ep emplace_back
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> __indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> __indexed_multiset;
const int sz = 3e5+9;
const int MOD = 1e9+7;
const int INF = 1e18;
int a[sz];

int n,k;

void solve()
{
    cin>>n>>k;
    --k;
    vector<int>v;
    for (int i = 1; i <= n; ++i)
    {
        cin>>a[i];
        v.ep(max(0LL,(a[i]-(a[i-1]+1))));
        //cerr<<"emplaced: "<<(max(0LL,(a[i]-(a[i-1]+1))))<<'\n';
    }
    sort(all(v));
    int res = a[n];
    while(!v.empty() && k)
    {
        res -= v.back();
        //cerr<<"pop: "<<(int)v.back()<<'\n';
        v.pop_back();
        --k;
    }
    cout<<res<<'\n';
}

signed main()
{
    $AzH_TxdmN$
    int t = 1;
    //cin>>t;
    while (t--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -