# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
921992 |
2024-02-04T16:03:38 Z |
IUA_Hasin |
Stove (JOI18_stove) |
C++17 |
|
1 ms |
348 KB |
#include <bits/stdc++.h>
#define endl "\n"
#define finp for(int i=0; i<n; i++)
#define fknp for(int k=0; k<n; k++)
#define yeap cout<<"YES"<<endl
#define nope cout<<"NO"<<endl
#define inpintn int n; cin>>n
#define inpintarrn int arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define inpllarrn long long arr[n]; for(int i=0; i<n; i++){cin>>arr[i];}
#define ll long long
#define pb push_back
#define answer cout<<ans<<endl
#define INF (ll)(1e18)
using namespace std;
int main ()
{
ll n, k;
cin>>n>>k;
ll arr[n];
ll brr[n-1];
vector<ll> v;
vector<ll> v1;
for(int i=0; i<n; i++){
if(i==0){
cin>>arr[i];
} else {
cin>>arr[i];
brr[i-1] = arr[i] - arr[i-1];
}
}
ll strt = arr[0];
for(int i=0; i<n-1; i++){
if(i==n-2){
if(brr[i]==1){
ll aa = arr[i+1]+1;
v.push_back(aa);
v1.push_back(strt);
} else {
ll aa = arr[i]+1;
v.push_back(aa);
v1.push_back(strt);
strt = arr[n-1];
aa = strt+1;
v.push_back(aa);
v1.push_back(strt);
}
} else if(brr[i]!=1){
ll aa = arr[i]+1;
v.push_back(aa);
v1.push_back(strt);
strt = arr[i+1];
}
}
ll siz = v.size();
ll crr[siz-1];
ll x = siz - 1;
for(int i=0; i<siz-1; i++){
crr[i] = v1[i+1] - v[i];
}
sort(crr, crr+x);
ll startt = 0;
ll ans = n;
if(n==1){
cout<<1<<endl;
} else if(n==2){
if(k>=2){
cout<<2<<endl;
} else {
ll aaa = arr[1] - arr[0] + 1;
cout<<aaa<<endl;
}
} else if(siz<=k){
cout<<ans<<endl;
} else {
while(siz>k){
ans+=crr[startt];
startt++;
siz--;
}
cout<<ans<<endl;
}
// for(int i=0; i<v.size(); i++){
// cout << v[i] << " ";
// }
// cout<<endl;
// for(int j=0; j<v1.size(); j++){
// cout << v1[j] << " ";
// }
// cout<<endl;
// for(int i=0; i<siz-1; i++){
// cout << crr[i] << " ";
// }
// cout<<endl;
// cout<<ans<<endl;
// cout << v1[2] << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |