제출 #229237

#제출 시각아이디문제언어결과실행 시간메모리
229237nickmet2004Stove (JOI18_stove)C++11
100 / 100
66 ms7156 KiB
#include<bits/stdc++.h> #define f first #define s second using namespace std; const int N = 2e5 + 500; typedef pair<int , int> ipair; int n , k; int a[N]; vector<ipair> deltas; set<int> s; int main (){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> k; for(int i = 0; i < n; ++i){ cin >> a[i]; if(i) deltas.emplace_back(a[i] - a[i - 1] , i - 1); } sort(deltas.begin() , deltas.end()); reverse(deltas.begin() , deltas.end()); for(int i = 0; i < k - 1; ++i){ s.insert(deltas[i].s); //cerr << deltas[i].s << " "; } //cerr << endl; long long sum = 0; int cur = 0; for(int x : s){ //cerr << x << " x " << "cur " << cur << endl; sum += (a[x] + 1 - a[cur]); //cerr << a[x] << " a[x] " << " acur " << a[cur] << endl; //cerr << sum << " sum " << endl; cur = x + 1; } sum += (a[n - 1] + 1 - a[cur]); cout << sum << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...