답안 #717185

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717185 2023-04-01T11:16:06 Z TimDee Stove (JOI18_stove) C++17
0 / 100
5 ms 6604 KB
//      ^                          ^ 
//      \\      ^ ^      ^ ^      //
//       \\___>(O.O)<  >(O_O)<___//
//       /  __ __ /      \ __ __  \
//      //// // //        \\ \\ \\\\

#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2,popcnt")

using ll = long long;
#define int long long
//#define double long double
#define forn(i,n) for(int i=0; i<(n); ++i)
#define pb push_back
#define pi pair<int,int>
#define f first
#define s second 
#define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i];
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e18;
const int mod = 1e9+7;//998244353;

const int N=1e5;

struct DSU {
    vector<int> p,r;
    DSU(int n) {
        forn(i,n) p.pb(i);
        forn(i,n) r.pb(0);
    }
    int get(int u) {
        return (p[u]==u)?u:get(p[u]);
    }
    void uni(int u, int v) {
        u=get(u), v=get(v);
        if (u==v) return;
        if (r[u]==r[v]) ++r[u];
        if (r[u]<r[v]) swap(u,v);
        p[v]=u;
    }
};
DSU dsu(N);
int ans[N];
set<int> stl[N];

void solve() {
    
    int n,k; cin>>n>>k;
    vector<int> a(n);
    for (int i=0; i<n; ++i) cin>>a[i];

    vector<int> b(n-1);
    for (int i=0; i<n-1; ++i) b[i]=a[i+1]-a[i]-1;

    sort(b.begin(), b.end());
    //acum b e sortat, adica b[i]<=b[i+1] pt orice i

                        //(sau ce era in problema)
    int ans = n; //pentru ca comp va lucra cel putin fiecare moment a[i];

    //acum avem n-1 intervale intre a[i] si a[i+1];
    //cand orim comp, 
    //noi il oprim imediat dupa un anumit a[i]
    //si il pornim la urmator a[i+1]
    //adica vrem sa alegem K CEI MAI MARI intervali
    //<=> adica adaugam la raspuns n-1-k cei mici
    for (int i=0; i<n-1-k; ++i) ans+=b[i];

    cout<<ans;

}
     
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t=1;
    //cin>>t;
    while (t--) solve();
    return 0;
}

Compilation message

stove.cpp:4:1: warning: multi-line comment [-Wcomment]
    4 | //       /  __ __ /      \ __ __  \
      | ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 6604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 6604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 6604 KB Output isn't correct
2 Halted 0 ms 0 KB -