이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll
const int N = 6e5;
const int INF = 1e9;
int n;
ll m, d, a[N];
bool check(int len) {
int SecHalf = -1;
for(int i = len; i >= 1; --i) {
if(m - d <= a[i]) {
SecHalf = i;
break;
}
}
//if(a[SecHalf] - d >= m) return 1;
ll pos = 0;
for(int i = 1; i <= len; ++i) {
if(i == SecHalf)
continue;
pos = pos + max(a[i] - abs(pos - d), 0ll);
}
pos = pos + max(a[SecHalf] - abs(pos - d), 0ll);
return (pos >= m);
}
main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> m >> d >> n;
fo(i, 1, n, 1) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
//cout << check(3);
int l = 1, r = n;
while(l < r) {
int mid = (l + r) / 2;
if(check(mid)) r = mid;
else l = mid + 1;
}
if(!check(r)) {
cout << 0;
return 0;
}
cout << r;
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
tak.cpp:54:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main () {
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |