Submission #1356440

#TimeUsernameProblemLanguageResultExecution timeMemory
1356440jona_fonsiStove (JOI18_stove)C++20
0 / 100
0 ms364 KiB
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define int long long
#define ull unsigned long long

#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define umap unordered_map
#define uset unordered_set
#define lb(v, x) lower_bound(all(v), x)
#define ub(v, x) upper_bound(all(v), x)

#define forr(i, a, b) for(int i = (int)(a); i <= (int)(b); i++)
#define forn(i, n) forr(i, 0, n-1)
#define ford(i, a, b) for(int i = (int)(a); i >= (int)(b); i--)

#define dbg(x) cout<<#x<<" : "<<x<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define ENDL cout<<endl

#define vi vector<int>
#define pii pair<int, int>
#define vvi vector<vi>
#define vii vector<pii>
#define vbool vector<bool>
#define vchar vector<char>
#define str string

const int mod = 1e9+7;
const int inf = LLONG_MAX;
const int mx = 2e5+5;

void setIO(string name = ""){
	if(!name.empty()){
		freopen((name + ".in").c_str(), "r", stdin);
		freopen((name + ".out").c_str(), "w", stdout);
	}
}

void red(int x){
	cout<<fixed<<setprecision(x);
}

void es(bool a){
	cout<<(a ? "YES" : "NO")<<endl;
}

void mos(vi v){
	for(int x : v) cout<<x<<" ";
	cout<<endl;
}

void mosm(vvi mt, int n, int m){
	ENDL;
	forn(i, n){
		forn(j, m) cout<<mt[i][j]<<" ";
		ENDL;
	}
}

void solve(){
    int n, k; cin>>n>>k;
    vi v(n), d;
    forn(i, n) cin>>v[i];
    forr(i, 1, n-1){
    	d.pb(v[i]-v[i-1]+1);
    }
    k--;
    int ans = 0;
    sort(rall(d));
    forn(i, k) ans += d[i];
    cout<<ans<<endl;
    //<mos(d);
    
}
/*
3 2
1
3
6

*/
int32_t main(){
    setIO; red(0);
    int t = 1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

Compilation message (stderr)

stove.cpp: In function 'void setIO(std::string)':
stove.cpp:52:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |                 freopen((name + ".in").c_str(), "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
stove.cpp:53:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |                 freopen((name + ".out").c_str(), "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...