提出 #34895485


ソースコード 拡げる

#include<stdio.h>
#define min(p,q)((p)<(q)?(p):(q))

int n;
long long k;
long long a[200010];

int f(long long m){
	long long s=0;
	for(int i=0;i<n;i++)s+=min(m,a[i]);
	return s<=k;
}

int main(){
	scanf("%d%lld",&n,&k);
	for(int i=0;i<n;i++)scanf("%lld",a+i);
	
	long long l=0,r=1e12+2;//l ok, r ng
	while(r-l>1){
		long long m=(l+r)/2;
		if(f(m))l=m;
		else r=m;
	}
	
	for(int i=0;i<n;i++){
		long long d=min(l,a[i]);
		a[i]-=d;
		k-=d;
	}
	
	for(int i=0;k>0;i++)if(a[i]){
		a[i]--;
		k--;
	}
	
	for(int i=0;i<n;i++)printf("%lld ",a[i]);
	puts("");
}

提出情報

提出日時
問題 E - Apple Baskets on Circle
ユーザ kyopro_friends
言語 C (GCC 9.2.1)
得点 500
コード長 589 Byte
結果 AC
実行時間 40 ms
メモリ 2520 KiB

コンパイルエラー

./Main.c: In function ‘main’:
./Main.c:15:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   15 |  scanf("%d%lld",&n,&k);
      |  ^~~~~~~~~~~~~~~~~~~~~
./Main.c:16:22: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
   16 |  for(int i=0;i<n;i++)scanf("%lld",a+i);
      |                      ^~~~~~~~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 2
AC × 26
セット名 テストケース
Sample sample_01.txt, sample_02.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 40 ms 2520 KiB
random_02.txt AC 26 ms 2136 KiB
random_03.txt AC 33 ms 2508 KiB
random_04.txt AC 29 ms 2312 KiB
random_05.txt AC 34 ms 2508 KiB
random_06.txt AC 34 ms 2420 KiB
random_07.txt AC 37 ms 2516 KiB
random_08.txt AC 15 ms 1928 KiB
random_09.txt AC 35 ms 2416 KiB
random_10.txt AC 35 ms 2308 KiB
random_11.txt AC 30 ms 2416 KiB
random_12.txt AC 20 ms 2088 KiB
random_13.txt AC 32 ms 2468 KiB
random_14.txt AC 26 ms 2224 KiB
random_15.txt AC 27 ms 2508 KiB
random_16.txt AC 7 ms 1704 KiB
random_17.txt AC 30 ms 2456 KiB
random_18.txt AC 28 ms 2428 KiB
random_19.txt AC 35 ms 2460 KiB
random_20.txt AC 2 ms 1680 KiB
random_21.txt AC 35 ms 2512 KiB
random_22.txt AC 5 ms 1628 KiB
random_23.txt AC 22 ms 2472 KiB
random_24.txt AC 1 ms 1684 KiB
sample_01.txt AC 2 ms 1684 KiB
sample_02.txt AC 1 ms 1640 KiB