# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1068527 | kiethm07 | Stove (JOI18_stove) | C++11 | 1 ms | 460 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pii pair<int,int>
#define iii pair<int,pii>
#define fi first
#define se second
#define vi vector<int>
#define vii vector<pii>
#define pb(i) push_back(i)
#define all(x) x.begin(),x.end()
#define TEXT "a"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int inf = 1e9 + 7;
const ld eps = 1e-8;
const double pi = acos(-1);
const int N = 1e5 + 5;
int a[N];
int n,k;
int check(int x){
int cnt = 1;
int total = 0;
int cur = 0;
for (int i = 2; i <= n; i++){
int t = a[i] - a[i - 1];
if (cur + t > x){
total += cur;
cur = 0;
cnt++;
}
else cur += t;
}
total += cur;
if (cnt > k) return -1;
return total;
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
if (fopen(TEXT".inp","r")){
freopen(TEXT".inp","r",stdin);
freopen(TEXT".out","w",stdout);
}
cin >> n >> k;
for (int i = 1; i <= n; i++) cin >> a[i];
int l = 1;
int r = inf;
int res = inf;
while(l <= r){
int mid = (l + r) / 2;
int t = check(mid);
if (t != -1){
r = mid - 1;
res = t + k;
}
else l = mid + 1;
}
cout << res << "\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |