Submission #9194374


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M, V, P, A[101010];
//---------------------------------------------------------------------------------------------------
bool check(int i) {
	int bigger = 0, less = 0;
	ll other = 0;
	rep(j, 0, N) if (j != i) {
		if (A[i] + M < A[j]) bigger++;
		else if (A[j] <= A[i]) less++;
		else other++;
	}

	if (P <= bigger) return false;
	
	ll rest = V - 1 - bigger - less;
	if (rest <= 0) return true;

	ll tot = 0;
	ll cnt = 0;
	rep(j, 0, N) if (A[i] < A[j] and A[j] <= A[i] + M) {
		tot += A[i] + M - A[j];
		
		cnt++;
		ll ok = min({ tot / M, other, rest });
		ll ng = rest - ok;
		if (bigger + ng < P and cnt + ng <= other) {
			return true;
		}
	}

	return false;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M >> V >> P;
	rep(i, 0, N) cin >> A[i];
	sort(A, A + N);

	int ng = -1, ok = N;
	while (ng + 1 != ok) {
		int md = (ng + ok) / 2;
		if (check(md)) ok = md;
		else ng = md;
	}

	int ans = N - ok;
	cout << ans << endl;
}





Submission Info

Submission Time
Task B - Voting Judges
User hamayanhamayan
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2354 Byte
Status
Exec Time 32 ms
Memory 640 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt
All 700 / 700 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt, 01-52.txt, 01-53.txt, 01-54.txt, 01-55.txt, 01-56.txt, 01-57.txt
Case Name Status Exec Time Memory
00-sample-01.txt 1 ms 256 KB
00-sample-02.txt 1 ms 256 KB
00-sample-03.txt 1 ms 256 KB
01-01.txt 1 ms 256 KB
01-02.txt 1 ms 256 KB
01-03.txt 1 ms 256 KB
01-04.txt 1 ms 256 KB
01-05.txt 1 ms 256 KB
01-06.txt 1 ms 256 KB
01-07.txt 1 ms 256 KB
01-08.txt 12 ms 512 KB
01-09.txt 18 ms 640 KB
01-10.txt 3 ms 256 KB
01-11.txt 3 ms 256 KB
01-12.txt 17 ms 640 KB
01-13.txt 12 ms 512 KB
01-14.txt 9 ms 384 KB
01-15.txt 12 ms 384 KB
01-16.txt 17 ms 640 KB
01-17.txt 5 ms 384 KB
01-18.txt 4 ms 384 KB
01-19.txt 20 ms 640 KB
01-20.txt 14 ms 512 KB
01-21.txt 19 ms 640 KB
01-22.txt 20 ms 640 KB
01-23.txt 19 ms 640 KB
01-24.txt 19 ms 640 KB
01-25.txt 19 ms 640 KB
01-26.txt 19 ms 640 KB
01-27.txt 21 ms 640 KB
01-28.txt 24 ms 640 KB
01-29.txt 21 ms 640 KB
01-30.txt 19 ms 640 KB
01-31.txt 12 ms 640 KB
01-32.txt 13 ms 640 KB
01-33.txt 17 ms 640 KB
01-34.txt 17 ms 640 KB
01-35.txt 19 ms 640 KB
01-36.txt 22 ms 640 KB
01-37.txt 19 ms 640 KB
01-38.txt 26 ms 640 KB
01-39.txt 30 ms 640 KB
01-40.txt 31 ms 640 KB
01-41.txt 28 ms 640 KB
01-42.txt 31 ms 640 KB
01-43.txt 21 ms 640 KB
01-44.txt 29 ms 640 KB
01-45.txt 30 ms 640 KB
01-46.txt 26 ms 640 KB
01-47.txt 26 ms 640 KB
01-48.txt 32 ms 640 KB
01-49.txt 20 ms 640 KB
01-50.txt 32 ms 640 KB
01-51.txt 31 ms 640 KB
01-52.txt 14 ms 640 KB
01-53.txt 13 ms 640 KB
01-54.txt 20 ms 640 KB
01-55.txt 19 ms 640 KB
01-56.txt 20 ms 640 KB
01-57.txt 20 ms 640 KB