Submission #1128615

#TimeUsernameProblemLanguageResultExecution timeMemory
1128615MathiasStove (JOI18_stove)C++20
100 / 100
16 ms1480 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define ull unsigned long long #define pb push_back #define fi first #define sc second #define vi vector<int> #define pii pair<int,int> #define vpi vector<pair<int,int> > #define mp make_pair const ll MOD1 = 1e9+7; const ll MOD2 = 998244353; const ll MOD3 = 1e9+93; const ll MOD4 = 1e9+97; const ll p1 = 1e9+87; const ll p2 = 1e9+9; const int INF = 1e9+7; const int BASE = 1<<20; const int LOG = 20; const int ALF = 27; const int MAXN = 1e6+7; const int MAXNN = 1e3+7; int t[MAXN]; vi diff; void solve(){ int n,k; ll res; cin>>n>>k; for(int i=1;i<=n;i++) cin>>t[i]; res=t[n]+1-t[1]; for(int i=2;i<=n;i++) diff.pb(t[i]-t[i-1]-1); sort(diff.begin(),diff.end()), reverse(diff.begin(),diff.end()); for(int i=0;i<k-1;i++) res-=diff[i]; cout<<res<<'\n'; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int tt=1; while(tt--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...