Submission #1052767

#TimeUsernameProblemLanguageResultExecution timeMemory
1052767whyalwaysmezzzStove (JOI18_stove)C++14
100 / 100
15 ms4828 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second #define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++) #define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--) #define BIT(mask,i) ((mask >> i) & 1ll ) #define endl '\n' #define all(x) x.begin(),x.end() #define ii pair <int,int> using namespace std; template<class X, class Y> bool minimize(X &x, const Y &y) { if (x > y) { x = y; return true; } else return false; } template<class X, class Y> bool maximize(X &x, const Y &y) { if (x < y) { x = y; return true; } else return false; } template<class T> T Abs(const T &x) { return (x < 0 ? -x : x); } const long long oo = 1e18; const int N = 1e6+5; const int MOD = 1e9+7; int a[N]; int n,k; int check(int x) { int cnt = 0; FOR(i,1,n-1) { if (a[i+1] - a[i] > x) cnt++; } return cnt; } void PhongCach() { cin >> n >> k; FOR(i,1,n) cin >> a[i]; vector <int> V; FOR(i,1,n-1) V.push_back(-a[i+1] + a[i]); sort(all(V)); int ans = a[n] - a[1] + k; FOR(i,0,k-2) ans+= V[i]; cout << ans; return; } #define TASK "task" signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(TASK".inp","r",stdin); //freopen(TASK".out","w",stdout); int Sty1e = 1; // cin >> Sty1e; while (Sty1e--) PhongCach(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...