Submission #883063

#TimeUsernameProblemLanguageResultExecution timeMemory
883063Huseyn123Stove (JOI18_stove)C++17
100 / 100
19 ms17728 KiB
#include <bits/stdc++.h>
#define MAX 200005
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second 
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
    for(int i=0;i<b;i++){\
        cin >> a[i];\
    }\
}
#define inputvec(a,b){\
    for(int i=0;i<b;i++){\
        ll num;\
        cin >> num;\
        a.pb(num);\
    }\
}
#define outputar(a,b){\
    for(int i=0;i<b;i++){\
        cout << a[i] << " ";\
    }\
    cout << "\n";\
}
#define outputvec(a){\
    for(auto x:a){\
        cout << x << " ";\
    }\
    cout << "\n";\
}
#define reset(a,n,v){\
    for(int i=0;i<n;i++){\
        a[i]=v;\
    }\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
  freopen((filename+".in").c_str(),"r",stdin);
  freopen((filename+".out").c_str(),"w",stdout);
}
ll n,q,t=1,m,n2,m2,k,x,y,z,x2,y2,z2,a[MAX],b[MAX],c[MAX],d[MAX],tim;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string s[MAX],str[MAX];
ll e[1001][1001];
string s1,s2;
const int mod = 998244353;
ll dx[4]={1,0,0,-1};
ll dy[4]={0,1,-1,0};
void solve(){
    cin >> n >> k; 
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<ll> c; 
    ll res=a[n-1]-a[0]+1;
    for(int i=0;i<n-1;i++){
        c.pb(a[i]-a[i+1]+1);
    }
    sortv(c); 
    for(int i=0;i<k-1;i++){
        res+=c[i]; 
    }
    cout << res << endl;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //USACO("diamond");
    //freopen("meta_game_input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cin >> t;
    ll cnt1=1;
    while(t--){
        //cout << "Case #" << cnt1 << ": ";
        solve();
        cnt1++;
    }
}
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
ll b[51][51];
b[0][0] = 1;
    for (int n = 1; n <= 50; ++n){
        b[n][0] = b[n][n] = 1;
        for (int k = 1; k < n; ++k)
            b[n][k] = b[n - 1][k - 1] + b[n - 1][k];
    }
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...