제출 #1177338

#제출 시각아이디문제언어결과실행 시간메모리
1177338NintsiChkhaidzeStove (JOI18_stove)C++20
100 / 100
12 ms2244 KiB
#include <iostream> #include <algorithm> #include <vector> #include <math.h> #include <cmath> #define int long long #define ff first #define ss second #define pb push_back #define pp pop_back #define all(x) x.begin(),x.end() #define pii pair<int,int> #define r0 return 0 using namespace std; const int N = 4 * 1e5 + 5, M = 5001, MOD = 998244353, modu = 1e9 + 7; int n,t,g,st,dr,q,l,asdw,r,d,u,k; int nash[N],suf[N],a[N]; vector <int> v; signed main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 2; i <= n; i++) { v.pb(a[i] - a[i - 1] - 1); } sort(all(v)); reverse(all(v)); int ans = a[n] - a[1] + 1; for (int i = 0; i < k - 1; i++) { ans -= v[i]; } cout << ans << endl; return 0; } //y - 1 - (x + 1) + 1 //y - 1 - x - 1 + 1 //y - x - 1;
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...