제출 #1286288

#제출 시각아이디문제언어결과실행 시간메모리
1286288LilPlutonStove (JOI18_stove)C++20
100 / 100
39 ms5904 KiB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
const int inf = 12345;
const int mod = 998244353;
void opd(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
}
struct BIT{
    int n;
    vector<int> ft;
    void init(int N){
        n = N;
        ft.assign(n + 1, 0);
    }
    void add(int pos, int val){
        while (pos <= n)
        {
            ft[pos] += val;
            pos += pos & -pos;
        }
    }
    int get(int pos){
        int res = 0;
        while (pos > 0)
        {
            res += ft[pos];
            pos -= pos & -pos;
        }
        return res;
    }
};

struct DSU
{
    vector<int>par, siz;
    int n;
    DSU(int N)
    {
        n = N + 5;
        par.resize(n + 1, 0);
        siz.assign(n + 1, 1);
        for(int i = 0; i <= n; ++i)
            par[i] = i;
    }
    int _find(int v)
    {
        if(par[v] == v)
            return v;
        return par[v] = _find(par[v]);
    }
    bool unite(int a, int b)
    {
        a = _find(a);
        b = _find(b);
        if(a != b)
        {
            if(siz[a] < siz[b])
                swap(a, b);
            siz[a] += siz[b];
            par[b] = a;
            return 1;
        }
        return 0;
    }
};

const int md = 1e9 + 7;
void solve(){
    int n, k;
    cin>>n>>k;
    int a[n+1];
    a[0]=-md;
    multiset<int>st;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        st.insert(a[i]-a[i-1]);
    }
    int res=k;
    n-=k;
    while(n--){
        res+=*st.begin();
        st.erase(st.begin());
    }
    cout<<res<<endl;
}

signed main(){
    ios::sync_with_stdio(0); cin.tie(0);
    //opd();
    int T = 1;
    while(T--){
        solve();
    }
    
}

컴파일 시 표준 에러 (stderr) 메시지

stove.cpp: In function 'void opd()':
stove.cpp:8:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    8 |     freopen("in.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
stove.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("out.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...