Submission #1049818

# Submission time Handle Problem Language Result Execution time Memory
1049818 2024-08-09T05:29:40 Z vjudge1 Stove (JOI18_stove) C++17
100 / 100
12 ms 4056 KB
#include <bits/stdc++.h>
using namespace std;

//typedef long long ll;
///typedef unsigned long long ull;
typedef pair<int,int> pi;
//typedef pair<long long,long long> pl;

#define all(s) s.begin(),s.end()
#define F first
#define S second
#define sz(a) a.size()
#define int long long

//const ll mod = 998244353;
//const ll mod1 = 1e9+7;
//const ll INF = 1e18;
const int N = 300200;
const int inf = 1e18+200;



int n,k;
int a[N];

vector<int> p;
int ans=0;

void solve() {
    cin>>n>>k;
    for(int i=1;i<=n;++i) {
        cin>>a[i];
    }
    a[n+1]=inf;
    for(int i=1,j=1;i<=n;++i) {
        if(a[i]+1!=a[i+1]) {
            p.push_back(a[i+1]-a[i]-1);
            ans+=(a[i]-a[j]+1);
            j=i+1;
        }
    }
    sort(all(p));
    int cnt=sz(p)-k;
    for(auto u:p) {
        if(cnt>0) {
            ans+=u;
            --cnt;
        }
        else {
            break;
        }
    }
    cout<<ans<<'\n';
}

signed main() {
    ios_base::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--) {
        solve();
    }
    return 0;
} 
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 11 ms 3844 KB Output is correct
17 Correct 12 ms 3800 KB Output is correct
18 Correct 11 ms 3848 KB Output is correct
19 Correct 11 ms 4056 KB Output is correct
20 Correct 11 ms 3804 KB Output is correct
21 Correct 11 ms 3800 KB Output is correct
22 Correct 11 ms 3804 KB Output is correct
23 Correct 11 ms 3672 KB Output is correct
24 Correct 11 ms 3804 KB Output is correct