# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
868904 | 2023-11-02T12:19:01 Z | autoastt | Stove (JOI18_stove) | C++14 | 1 ms | 348 KB |
#include<bits/stdc++.h> using namespace std; const int N=1e5+5; int a[N], b[N], ans, cnt; int main(){ int n, k; cin >> n >> k; vector<pair<int,pair<int,int>>> v; for(int i=0;i<n;i++){ cin >> a[i]; if(i>0) v.push_back({a[i]-a[i-1]+1,{i,i-1}}); } sort(v.begin(),v.end()); for(int i=0,j=0;i<v.size();i++){ ans+=v[i].first; j++; //cout << j << ' ' << ans << "\n"; if(!b[v[i].second.first]) b[v[i].second.first]=1,cnt++; if(!b[v[i].second.second]) b[v[i].second.second] = 1,cnt++; if(n-cnt+j==k){ cout << ans+j; return 0; } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |