답안 #713153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
713153 2023-03-21T08:47:59 Z ln_e Stove (JOI18_stove) C++17
0 / 100
1 ms 332 KB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
ll const MAX_N=3e5+5;
ld const EPS=0.00000001;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(a) (int)a.size()
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,k,a[100005];
int32_t main(){
CODE_START;
#ifdef LOCAL
ifstream cin("input.txt");
#endif
cin>>n>>k;
for(ll i=1;i<=n;i++)
{
    cin>>a[i];
}
if(n==k){
    cout<<n<<endl;
    return 0;
}
vector<ll>v;
for(ll i=1;i<=n;i++)
{
    v.pb(a[i]-a[i-1]);
}
sort(v.begin(),v.end());
ll ans=k-1;
for(ll i=0;i<n-k+1;i++)
{
    ans+=v[i];
}
cout<<ans<<endl;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -