이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
const long long N = 100100;
const long long Q = N * 30;
const long long mod = 998244353;
const long long MAGIC = 30;
using namespace std;
int n;
int k;
int a[N];
vector < int > v;
pair < long long, int > d[N];
pair < long long, int > get(long long f)
{
pair < long long, int > mn = {- a[1], 0};
for(int i = 1; i <= n; i++){
d[i] = {mn.fi + a[i] + f, mn.se + 1};
mn = min(mn, {d[i].fi - a[i + 1], d[i].se});
}
return d[n];
}
void solve()
{
cin >> n >> k;
long long ans = 0;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
sort(a + 1, a + n + 1);
long long l = 0, r = 1e12;
while(l < r){
long long m = (l + r) / 2;
if(get(m).se > k){
l = m + 1;
}
else{
r = m;
}
}
cout << get(l).fi - k * l + k << "\n";
}
bool mtest = false; int main()
{
//fin("input.txt");
//fout("output.txt");
//fin("island.in");
//fout("island.out");
ios_base::sync_with_stdio(0);
int TE = 1;
if(mtest)
cin >> TE;
while(TE--)
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
stove.cpp: In function 'void solve()':
stove.cpp:34:19: warning: unused variable 'ans' [-Wunused-variable]
long long ans = 0;
^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |