답안 #228396

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228396 2020-04-30T22:23:58 Z tushar_2658 쌀 창고 (IOI11_ricehub) C++14
0 / 100
97 ms 640 KB
#include "ricehub.h"
#include "bits/stdc++.h"
using namespace std;

const int maxn = 100005;
using ll = long long;

int a[maxn];
ll lim;
vector<ll> p;
int n;

int besthub(int R, int L, int X[], long long B)
{
	n = R;
	lim = B;
	p.resize(R);
	for(int i = 0; i < R; ++i){
		a[i] = X[i];
	}
	sort(a, a + R);
	for(int i = 0; i < R; ++i){
		if(i == 0){
			p[i] = a[i];
		}else {
			p[i] = p[i - 1] + a[i];
		}
	}
  int ans = 0;
  for(int i = 0; i < n; ++i){
  	ll mid = a[i];
  	int l = i, r = i;
  	ll left = B;
  	int done = 0;
  	while(left > 0 && r < n && l >= 0){
  		ll nxt_l = LLONG_MAX;
  		if(l > 0){
  			nxt_l = a[l] - a[l - 1];
  		}
  		ll nxt_r = LLONG_MAX;
  		if(r < n - 1){
  			nxt_r = a[r + 1] - a[r];
  		}
  		if(nxt_l < nxt_r){
  			done++;
  			left -= nxt_l;
  			--l;
  		}else {
  			done++;
  			left -= nxt_r;
  			++r;
  		}
  	}
  	ans = max(ans, done);
  }
  return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:31:7: warning: unused variable 'mid' [-Wunused-variable]
    ll mid = a[i];
       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Incorrect 4 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 97 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -