제출 #1296250

#제출 시각아이디문제언어결과실행 시간메모리
1296250nikaa123Stove (JOI18_stove)C++20
100 / 100
20 ms2624 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define eb emplace_back #define mp make_pair #define pb push_back #define pp pop_back #define endl '\n' #define ff first #define ss second #define stop exit(0) #define sz(x) (int)x.size() #define pause system("pause") #define all(x) (x).begin(), (x).end() #define deb(x) cout << #x << "-" << x << endl mt19937 mt(time(nullptr)); typedef char chr; typedef string str; typedef long long ll; typedef vector<int> vii; typedef pair<int, int> pii; const long long INF = LLONG_MAX; const int inf = INT_MAX; const int mod = 1000003; const int MOD = 1000000007; const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1}; const double PI = 2 * acos(0.0); const int N = 1e6+5; int n,k,a[N]; vector <int> res; inline void test_case() { cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } if (k >= n) { cout << n << endl; return; } for (int i = 1; i <= n; i++) { if (i == n) continue; res.pb(a[i+1]-a[i]-1); } sort(all(res),greater<int>()); int ans = a[n]-a[1]+1; // deb(n-k-1); for (int i = 0; i < k-1; i++) { // deb(res[i]); ans -= res[i]; } cout << ans << endl; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; while (T--) test_case(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...