提出 #58279635


ソースコード 拡げる

/* cmdS
	g++ -std=gnu++17 -O3 -o a "$F"
*/
#include <algorithm>
#include <iostream>

int N,M;
int64_t X,K,A[200000],B[200000],S[200001];
using namespace std;

int main()
{
	cin>>N>>M>>K;
	for (int i = 0; i < N; ++i) {
		cin>>A[i];
		B[i] = A[i];
	}
	sort(B,B+N,greater<int64_t>());

	if (N==M) {
		for (int i = 0; i < N; ++i) {
			cout<<0<<(i==N-1 ? "\n" : " ");
		}
	} else {
		S[0] = 0;
		for (int i = 0; i < N; ++i) {
			S[i+1] = S[i]+B[i];
		}
		X = K-S[N];
		for (int i = 0; i < N; ++i) {
			int64_t a = A[i];
			int k = lower_bound(B,B+N,a,greater<int64_t>())-B;
			int64_t s = (M<=k) ? S[M] : S[M+1]-a;
			auto p = [&](int64_t x){
				int64_t b = a+x+1;
				int k = upper_bound(B,B+N,b,greater<int64_t>())-B;
				k = min(k,M);
				int64_t t = s-S[k]+b*k;
				return X-x < b*M-t;
			};
			if (p(0)) {
				cout<<0<<(i==N-1 ? "\n" : " ");
			} else if (! p(X)) {
				cout<<-1<<(i==N-1 ? "\n" : " ");
			} else {
				int64_t l = 0,r = X;
				while (l+1 < r) {
					int64_t m = l+(r-l)/2;
					if (p(m)) {
						r = m;
					} else {
						l = m;
					}
				}
				cout<<r<<(i==N-1 ? "\n" : " ");
			}
		}
	}
	
	return 0;
}

提出情報

提出日時
問題 E - How to Win the Election
ユーザ ds14050
言語 C++ 17 (gcc 12.2)
得点 500
コード長 1185 Byte
結果 AC
実行時間 303 ms
メモリ 8304 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 43
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 02_hand_00.txt, 02_hand_01.txt, 02_hand_02.txt, 02_hand_03.txt, 02_hand_04.txt, 02_hand_05.txt, 02_hand_06.txt, 02_hand_07.txt, 02_hand_08.txt, 02_hand_09.txt, 02_hand_10.txt, 02_hand_11.txt, 03_large_k_00.txt, 03_large_k_01.txt, 03_large_k_02.txt, 03_large_k_03.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3480 KiB
00_sample_01.txt AC 1 ms 3436 KiB
01_random_00.txt AC 110 ms 5552 KiB
01_random_01.txt AC 169 ms 6076 KiB
01_random_02.txt AC 220 ms 7948 KiB
01_random_03.txt AC 182 ms 7240 KiB
01_random_04.txt AC 191 ms 6180 KiB
01_random_05.txt AC 232 ms 8264 KiB
01_random_06.txt AC 1 ms 3496 KiB
01_random_07.txt AC 1 ms 3500 KiB
01_random_08.txt AC 1 ms 3508 KiB
01_random_09.txt AC 1 ms 3612 KiB
01_random_10.txt AC 1 ms 3492 KiB
01_random_11.txt AC 1 ms 3516 KiB
01_random_12.txt AC 264 ms 8180 KiB
01_random_13.txt AC 233 ms 8180 KiB
01_random_14.txt AC 235 ms 8220 KiB
01_random_15.txt AC 229 ms 8188 KiB
01_random_16.txt AC 230 ms 8304 KiB
01_random_17.txt AC 234 ms 8172 KiB
01_random_18.txt AC 303 ms 8176 KiB
01_random_19.txt AC 242 ms 8156 KiB
01_random_20.txt AC 146 ms 8228 KiB
01_random_21.txt AC 145 ms 8160 KiB
01_random_22.txt AC 84 ms 8168 KiB
01_random_23.txt AC 83 ms 8280 KiB
01_random_24.txt AC 149 ms 8192 KiB
02_hand_00.txt AC 170 ms 8180 KiB
02_hand_01.txt AC 174 ms 8216 KiB
02_hand_02.txt AC 177 ms 8216 KiB
02_hand_03.txt AC 170 ms 8224 KiB
02_hand_04.txt AC 175 ms 8176 KiB
02_hand_05.txt AC 170 ms 8224 KiB
02_hand_06.txt AC 175 ms 8216 KiB
02_hand_07.txt AC 175 ms 8284 KiB
02_hand_08.txt AC 35 ms 8300 KiB
02_hand_09.txt AC 61 ms 8112 KiB
02_hand_10.txt AC 70 ms 8112 KiB
02_hand_11.txt AC 63 ms 6612 KiB
03_large_k_00.txt AC 16 ms 4276 KiB
03_large_k_01.txt AC 14 ms 4276 KiB
03_large_k_02.txt AC 96 ms 7072 KiB
03_large_k_03.txt AC 8 ms 3712 KiB