제출 #678194

#제출 시각아이디문제언어결과실행 시간메모리
678194vjudge1Stove (JOI18_stove)C++17
100 / 100
27 ms2192 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define ll long long #define ull unsigned long long #define len(x) (int)x.size() #define all(x) (x).begin(), (x).end() #define F first #define S second using namespace std; const ll MOD = 1e9 + 7; ll power (ll a, ll b) { ll result = 1; for (int i = 1; i <= b; i++) result *= a; return result; } ll binpow(ll a, ll b) { if (b == 0) return 1; if (b % 2 == 1) return binpow(a, b - 1) * a; else return binpow(a, b / 2) * binpow(a, b / 2); } ll fact(int x) { ll result = 1; for (int i = 2; i <= x; i++) result *= i; return result; } ll comb(int n, int k) { return fact(n) / fact(k) / fact(n - k); } void dpcomb(){ int c[2][2]; c[1][1] = 1; for (int n = 2; n <= 1000; n++) { c[n][1] = n; for (int k = 2; k <= n; k++) { c[n][k] = (c[n - 1][k] + c[n - 1][k - 1]) % MOD; } } } int a[100001]; vector < int > p; int main() { //freopen("success.in", "r", stdin); //freopen("success.out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k; cin >> n >> k >> a[1]; for (int i = 2; i <= n; i++) { cin >> a[i]; p.pb(a[i - 1] + 1 - a[i]); } sort(all(p)); ll sum = 0; for (int i = 0; i < k - 1; i++) { sum += p[i]; } cout << sum - a[1] + a[n] + 1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...