Submission #1033676

#TimeUsernameProblemLanguageResultExecution timeMemory
1033676anHiepStove (JOI18_stove)C++14
100 / 100
14 ms2268 KiB
//#pragma GCC optimize("O3,unroll-loops") //#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define ll long long #define ii pair<int, int> #define vi vector<int> #define vll vector<ll> #define vii vector<ii> #define cd complex<double> #define ld long double #define all(x) (x).begin(), (x).end() #define iii tuple<int, int, int> const ll mod = 1e9 + 7; const ll INF = 1e18L + 5; const double PI = acos(-1); const int block = 320; const int N = 2e5; int tc, tt = 1; int n, k; vll f; void solve() { cin>>n>>k; f.resize(n); for(int i=0; i<n; i++) cin>>f[i]; vll g; for(int i=1; i<(int)f.size(); i++) g.pb(f[i] - f[i - 1] - 1); sort(g.begin(), g.end(), greater<ll>()); ll ans = (int)f.size(); for(int i=1; i<=n-k; i++) { ans += g.back(); g.pop_back(); } cout<<ans; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for(tc=1; tc<=tt; tc++) solve(); cerr<<"\nTime elapsed: "<<1000.0*clock()/CLOCKS_PER_SEC<<" ms.\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...