답안 #966456

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966456 2024-04-19T23:00:04 Z Aliyyiakbar Stove (JOI18_stove) C++17
100 / 100
18 ms 4056 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;
    int res = n;
    for (int i = 1; i <= n; ++i)
    {
        cin>>a[i];
        if (i > 1)      v.ep(a[i]-(a[i-1]+1)), res += v.back();
        //cerr<<"emplaced: "<<(max(0LL,(a[i]-(a[i-1]+1))))<<'\n';
    }
    sort(all(v));
    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();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 456 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 456 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 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 456 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 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 15 ms 4056 KB Output is correct
17 Correct 15 ms 3804 KB Output is correct
18 Correct 16 ms 3804 KB Output is correct
19 Correct 15 ms 3804 KB Output is correct
20 Correct 15 ms 3804 KB Output is correct
21 Correct 15 ms 3748 KB Output is correct
22 Correct 18 ms 3860 KB Output is correct
23 Correct 15 ms 4056 KB Output is correct
24 Correct 15 ms 3804 KB Output is correct