답안 #28961

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
28961 2017-07-18T02:03:45 Z 윤교준(#1230) Taxis (POI13_tak) C++11
100 / 100
189 ms 5924 KB
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define revv(V) reverse(allv(V))
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define MAXN (500005)
using namespace std;
typedef long long ll;

ll A[MAXN];
ll L, R;
int N, Ans = INF, Hi;

int main() {
	scanf("%lld%lld%d", &R, &L, &N);
	for(int i = 0; i < N; i++) scanf("%lld", &A[i]);
	sort(A, A+N);
	for(int i = 0; i <= N; i++) {
		if(i < N && A[i] < R-L) continue;
		int cnt = 0, j = N-1; ll x = 0;
		ll cx = (i == N) ? L : min(L, max(0ll, L - (A[i] - (R-L))/2));
		for(; ~j && x < cx && cnt < Ans; j--) {
			if(i == j) continue;
			if(A[j] < L-x) break;
			x += A[j] - (L-x); cnt++;
		}
		if(Ans <= cnt) continue;
		if(R <= x) upmin(Ans, cnt);
		if(i == N) continue;
		if(L <= x && R-L <= A[i]) upmin(Ans, cnt+1);
		else if(x < L && (L-x)*2 + (R-L) <= A[i]) upmin(Ans, cnt+1);
	}
	printf("%d\n", INF <= Ans ? 0 : Ans);
	return 0;
}

Compilation message

tak.cpp: In function 'int main()':
tak.cpp:23:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%d", &R, &L, &N);
                                 ^
tak.cpp:24:49: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < N; i++) scanf("%lld", &A[i]);
                                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5924 KB Output is correct
2 Correct 0 ms 5924 KB Output is correct
3 Correct 0 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5924 KB Output is correct
2 Correct 0 ms 5924 KB Output is correct
3 Correct 0 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5924 KB Output is correct
2 Correct 0 ms 5924 KB Output is correct
3 Correct 0 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 5924 KB Output is correct
2 Correct 0 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 5924 KB Output is correct
2 Correct 3 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 5924 KB Output is correct
2 Correct 19 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 39 ms 5924 KB Output is correct
2 Correct 59 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 5924 KB Output is correct
2 Correct 106 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 189 ms 5924 KB Output is correct
2 Correct 153 ms 5924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 5924 KB Output is correct
2 Correct 169 ms 5924 KB Output is correct