Submission #953571

#TimeUsernameProblemLanguageResultExecution timeMemory
953571batsukh2006Stove (JOI18_stove)C++17
100 / 100
15 ms3540 KiB
#include<iostream> #include<stdio.h> #include<math.h> #include<map> #include<string> #include<algorithm> #include<vector> #include<string.h> #include<utility> #include<set> #include<cmath> #include<queue> #include<deque> #include<functional> #include<stack> #include<limits.h> #include<iomanip> #include<unordered_map> #include<numeric> #include<tuple> #include<bitset> using namespace std; #define MOD 1000000007 #define int long long #define endl '\n' void solve(){ int n,k; cin>>n>>k; vector<int> a(n+1); for(int i=1; i<=n; i++) cin>>a[i]; vector<int> gap; int big=a[n]-a[1]+1; for(int i=2; i<=n; i++){ gap.push_back(a[i]-a[i-1]-1); } sort(gap.begin(),gap.end(),greater<int>()); for(int i=0; i<k-1; i++) big-=gap[i]; cout<<big; } signed main(){ // freopen("file.in", "r", stdin); // freopen("file.out", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int T=1; // cin>>T; while(T--){ solve(); cout<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...