답안 #348661

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348661 2021-01-15T14:11:03 Z idk321 쌀 창고 (IOI11_ricehub) C++11
0 / 100
4 ms 620 KB
#include "ricehub.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 100005;
int pos[N];

int n;
long long money;

bool poss(int len)
{
    ll cost = 0;
    int a = 0;
    int b = len - 1;
    int mid = (a + b) / 2;
    int left = 0;
    int right = 0;
    for (int i = a; i <= b; i++)
    {
        cost += abs(pos[i] - pos[mid]);
        if (pos[i] < pos[mid]) left++;
        if (pos[i] > pos[mid]) right++;
    }

    cout << len << " " << cost << " " << money << endl;
    if (cost <= money) return true;
    while (b + 1 < n)
    {
        cost -= pos[mid] - pos[a];
        cost += (ll) (left) * (pos[mid + 1] - pos[mid]);
        cost -= (ll) (right) * (pos[mid + 1] - pos[mid]);
        mid++;
        a++;
        b++;
        cost += pos[b] - pos[mid];
        if (cost <= money) return true;
    }

    return false;
}

int binarySearch()
{
    int a = 1;
    int b = n;
    int res = -1;
    while (a <= b)
    {
        int mid = (a + b) / 2;
        if (poss(mid))
        {
            res = mid;
            a = mid + 1;
        } else
        {
            b = mid - 1;
        }
    }

    return res;
}

int besthub(int n1, int l, int x[], long long money1)
{
    money = money1;
    n = n1;
    for (int i = 0; i < n; i++)
    {
        pos[i] = x[i];
    }

  return binarySearch();
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 620 KB Output isn't correct
2 Halted 0 ms 0 KB -