답안 #921988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921988 2024-02-04T16:00:07 Z IUA_Hasin Stove (JOI18_stove) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>
 
#define endl                                "\n"
#define finp                                for(int i=0; i<n; i++)
#define fknp                                for(int k=0; k<n; k++)
#define yeap                                cout<<"YES"<<endl
#define nope                                cout<<"NO"<<endl
#define inpintn                             int n; cin>>n
#define inpintarrn                          int arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define inpllarrn                           long long arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define ll                                  long long
#define pb                                  push_back
#define answer                              cout<<ans<<endl
#define INF                                 (ll)(1e18)
 
 
using namespace std;
 
int main ()
{ 
    ll n, k;
    cin>>n>>k;
    ll arr[n];
    ll brr[n-1];
    vector<ll> v;
    vector<ll> v1;
    for(int i=0; i<n; i++){
        if(i==0){
            cin>>arr[i];
        } else {
            cin>>arr[i];
            brr[i-1] = arr[i] - arr[i-1]; 
        }
    }

    ll strt = arr[0];

    for(int i=0; i<n-1; i++){
        if(i==n-2){
            if(brr[i]==1){
                ll aa = arr[i+1]+1;
                v.push_back(aa);
                v1.push_back(strt);
            } else {
                ll aa = arr[i]+1;
                v.push_back(aa);
                v1.push_back(strt);
                strt = arr[n-1];
                aa = strt+1;
                v.push_back(aa);
                v1.push_back(strt);
            }
        } else if(brr[i]!=1){
            ll aa = arr[i]+1;
            v.push_back(aa);
            v1.push_back(strt);
            strt = arr[i+1];
        }
    }

    ll siz = v.size();
    ll crr[siz-1];
    ll x = siz - 1;
    for(int i=0; i<siz-1; i++){
        crr[i] = v1[i+1] - v[i];
    }
    sort(crr, crr+x);
    ll startt = 0;
    ll ans = n;
    if(siz<=k){
        cout<<ans<<endl;
    } else {
        while(siz>k){
            ans+=crr[startt];
            startt++;
            siz--;
        }
        cout<<ans<<endl;
    }   



    // for(int i=0; i<v.size(); i++){
    //     cout << v[i] << " ";
    // }

    // cout<<endl;

    // for(int j=0; j<v1.size(); j++){
    //     cout << v1[j] << " ";
    // }
    // cout<<endl;

    // for(int i=0; i<siz-1; i++){
    //     cout << crr[i] << " ";
    // }

    // cout<<endl;

    // cout<<ans<<endl;

    // cout << v1[2] << endl;


    return 0;
 
 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 1 ms 348 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 1 ms 348 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Runtime error 1 ms 348 KB Execution killed with signal 11
10 Halted 0 ms 0 KB -