제출 #1257406

#제출 시각아이디문제언어결과실행 시간메모리
1257406den1z19Stove (JOI18_stove)C++20
100 / 100
13 ms1864 KiB
#include "bits/stdc++.h" #define endl '\n' #define pb push_back #define all(a) (a).begin(), (a).end() #define rall(a) (a).rbegin(), (a).rend() using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<ll> vl; typedef vector<int> vi; typedef vector<char> vc; typedef vector<string> vs; typedef vector<int>::iterator vit; typedef set<int> si; typedef map<int, int> mii; void solve() { ll n , k ,tmp; cin >> n >> k; vl a(n); for ( ll i = 0 ; i< n ; i++){ cin >>a[i]; } vl b(n-1); for ( ll i = 0; i<n-1; i++){ b[i]= a[i+1] - a[i]; } sort(all(b)); reverse(all(b)); ll ans = min((ll)a.size(),k); for(ll i = k-1; i< n-1; i++){ ans += b[i]; } cout << ans << endl; } int main() { std::ios::sync_with_stdio(false); cin.tie(nullptr); unsigned long long ct = 1; //cin >> ct; while (ct--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...