제출 #1137860

#제출 시각아이디문제언어결과실행 시간메모리
1137860vtnooStove (JOI18_stove)C++20
100 / 100
31 ms2756 KiB
#include<bits/stdc++.h> #define pb push_back #define snd second #define fst first #define forn(i,n) for(int i=0;i<n;++i) #define forsn(i,UwU,n) for(int i=UwU; i<n; ++i) #define SIZE(c) int((c).size()) #define all(x) x.begin(), x.end() #define imp(x) {for(auto __:x)cout<<__<<" "; cout<<endl;} #define DBG(x) cerr << #x << " = " << (x) << endl #define RAYA cerr << "===============================" << endl using namespace std; typedef long long ll; typedef pair<ll,ll> ii; typedef vector<ll> vi; inline void FIO() {ios_base::sync_with_stdio(false); cin.tie(NULL);} int main(){FIO; int n,k;cin>>n>>k; vi a(n), diff(n); forn(i,n)cin>>a[i]; forsn(i,1,n){ diff.pb(a[i]-a[i-1]); } sort(all(diff)); reverse(all(diff)); ll res=0; forn(i,k-1){ res+=diff[i]; } cout<<a[n-1]-a[0]-res+k<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...