Submission #1306544

#TimeUsernameProblemLanguageResultExecution timeMemory
1306544xosqedemrufoStove (JOI18_stove)C++20
100 / 100
15 ms2380 KiB
//Author RufatM #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include <ext/pb_ds/detail/standard_policies.hpp> using namespace __gnu_pbds; using namespace std; typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vector<int>> vvi; typedef vector<ll> vll; typedef vector<bool> vb; typedef vector<string> vs; #define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define endl '\n' #define pb push_back #define pf push_front #define eb emplace_back #define ff first #define ss second #define all(x) begin(x),end(x) #define rall(x) rbegin(x),rend(x) #define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> const int MOD=1e9+7; const int INF=1e9; const ll LINF=1e18; const int MAXN=2e6; void solve(){ int n,k; cin >> n >> k; vll a(n); for(int i=0;i<n;i++){ cin >> a[i]; } if(n<=k){ cout << n << endl; return; } vll ans; for(int i=0;i<n-1;i++){ ans.pb(a[i+1]-a[i]-1); } sort(rall(ans)); ll total = a[n-1]+1-a[0]; for(int i=0;i<k-1;i++){ if(i<ans.size()){ total -= ans[i]; } } cout << total << endl; } signed main(){ fastio; int t=1; //cin >> t; while(t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...