Submission #569577

#TimeUsernameProblemLanguageResultExecution timeMemory
569577HuyStove (JOI18_stove)C++17
100 / 100
23 ms3008 KiB
#include<bits/stdc++.h> #define int long long #define pii pair<int,int> #define fi first #define se second using namespace std; using ll = long long; using ldb = long double; const int N = (int)1e8; const int maxN = (int)1e6 + 1; const int mod = 1e9 + 7; void InputFile() { //freopen("scrivener.inp","r",stdin); //freopen("scrivener.out","w",stdout); //freopen("test.out","r",stdin); } void FastInput() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int n,k; int T[maxN]; vector<int> su; int res = 0; void Read() { cin >> n >> k; for(int i = 1;i <= n;i++) { cin >> T[i]; if(i > 1) { res += T[i] - T[i-1]; su.push_back(T[i] - T[i-1]); } } if(n == 1) {cout << 1;return;} sort(su.begin(),su.end(),greater<int>()); for(int i = 0;i < k - 1;i++) { res -= su[i]; } res += k; cout << res; } void Solve() { } void Debug() { //Main_sub(); //Naive(); } int32_t main() { FastInput(); //InputFile(); //int sub_type; //cin >> sub_type; //Sieve(); int test; //cin >> test; test = 1; while(test--) //for(int prc = 1; prc <= test; prc++) { Read(); Solve(); //Debug(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...