Submission #270570

#TimeUsernameProblemLanguageResultExecution timeMemory
270570aymane7Stove (JOI18_stove)C++17
100 / 100
21 ms1152 KiB
#include<bits/stdc++.h> #pragma GCC optimize("O2") #define F first #define S second #define PB push_back #define MP make_pair #define all(c) c.begin(), c.end() #define endl "\n" #define sz(u) (int)(u.size()) #define L(x)(2*x) #define R(x)(2*x+1) #define M(x,y)((x+y)/2) typedef long long ll; typedef unsigned long long ull; using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,k; cin>>n>>k; int t[n+1],diff[n+1]; for(int i=1;i<=n;i++) cin>>t[i]; for(int i=2;i<=n;i++) diff[i]=t[i]-t[i-1]; sort(diff+2,diff+n+1); int cnt=0; for(int i=2;i<=n;i++){ if(i>n-k+1) cnt+=1; else cnt+=diff[i]; } cout<<cnt+1; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...