제출 #234938

#제출 시각아이디문제언어결과실행 시간메모리
234938AtalasionStove (JOI18_stove)C++14
100 / 100
28 ms2336 KiB
//khodaya khodet komak kon #include <bits/stdc++.h> #define F first #define S second #define pb push_back #define all(x) x.begin(), x.end() #pragma GCC optimize ("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC optimize ("-O2") using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef vector<int> vi; const int N = 200000 + 10; const ll MOD = 1000000000 + 7; const ll INF = 1000000010; const ll LOG = 25; int a[N], n, k; int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; vector<int> num; ll sm = 0; for (int i = 1; i <= n; i++){ cin >> a[i]; if (i > 1) num.pb(a[i] - a[i - 1] - 1); } sm = a[n] - a[1] + 1; sort(all(num)); reverse(all(num)); for (int i = 0; i < k - 1; i++) sm -= num[i]; cout << sm; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...