제출 #37054

#제출 시각아이디문제언어결과실행 시간메모리
37054szawinisTaxis (POI13_tak)C++14
80 / 100
1000 ms5920 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e5+1;

int n;
ll m, d, x[N];

bool check(int lim_idx) {
  bool ret = 0;
  for (int rem = 1; rem <= lim_idx; rem++) {
    ll curr = 0;
    for (int i = 1; i < rem && curr < d; i++)
      curr += max(x[i] - (d - curr), 0ll);
    for (int i = rem + 1; i <= lim_idx && curr < d; i++)
      curr += max(x[i] - (d - curr), 0ll);
		if(curr < d) ret |= x[rem] - 2 * (d - curr) >= m - d;
		else ret |= x[rem] >= m - d;
  }
	return ret;
}

int main() {
	scanf("%lld %lld %d", &m, &d, &n);
	for(int i = 1; i <= n; i++) scanf("%lld", x+i);
	sort(x+1, x+n+1, greater<ll>());
	int l = 1, r = n;
	while(l < r) {
		int mid = l+r >> 1;
		if(check(mid)) r = mid;
		else l = mid+1;
	}
	if(!check(l)) printf("0");
	else printf("%d", l);
}

컴파일 시 표준 에러 (stderr) 메시지

tak.cpp: In function 'int main()':
tak.cpp:29:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l+r >> 1;
              ^
tak.cpp:24:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %d", &m, &d, &n);
                                   ^
tak.cpp:25:48: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 1; i <= n; i++) scanf("%lld", x+i);
                                                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...