#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define fi first
#define se second
#define space " "
#define endl "\n"
#define gcd __gcd
#define mp make_pair
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define md 1000000007
#define inf 1000000000
#define li 500005
#define int long long
using namespace std;
int T,Q,n,m,a[li];
string s,t;
vector<pair<int,int> > v,vv;
int32_t main(){
scanf("%lld %lld",&n,&m);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=n;i++){
v.pb(mp(a[i],a[i]+1));
}
int sayi=n-m;
while(sayi--){
vv.clear();
int mn=inf+1;
for(int i=0;i<(int)v.size()-1;i++){
mn=min(mn,v[i+1].fi-v[i].se);
}
int tut=0;
for(int i=0;i<(int)v.size()-1;i++){
if(v[i+1].fi-v[i].se==mn){tut=i; break;}
}
for(int i=0;i<tut;i++) vv.pb(mp(v[i].fi,v[i].se));
vv.pb(mp(v[tut].fi,v[tut+1].se));
for(int i=tut+2;i<(int)v.size();i++) vv.pb(mp(v[i].fi,v[i].se));
v.clear();
v=vv;
}
int cev=0;
for(int i=0;i<(int)v.size();i++){
cev+=v[i].se-v[i].fi;
}
printf("%lld\n",cev);
return 0;
}
Compilation message (stderr)
stove.cpp: In function 'int32_t main()':
stove.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%lld %lld",&n,&m);
| ~~~~~^~~~~~~~~~~~~~~~~~~
stove.cpp:25:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |