結果

問題 No.2501 Maximum Inversion Number
ユーザー tailstails
提出日時 2023-10-13 22:46:49
言語 cLay
(20240104-1)
結果
WA  
実行時間 -
コード長 399 bytes
コンパイル時間 3,469 ms
コンパイル使用メモリ 163,824 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-10-13 22:46:54
合計ジャッジ時間 3,621 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

ll@t;
rep(t){
	ll@n,@m,@l[n],@r[n];

	ll a=-1,b=m+2;
	while(a+1<b){
		ll c=a+b>>1;
		ll s=0;
		rep(i,n){
			s+=min(max(c,l[i]),r[i]);
		}
		if(s<=m){
			a=c;
		}else{
			b=c;
		}
	}
	if(a<0||a>m){
		wt(-1);
	}else{
		ll s=m;
		rep(i,n){
			s-=min(max(a,l[i]),r[i]);
		}
		ll y=0,z=0;
		rep(i,n){
			ll x=min(max(a,l[i]),r[i]);
			if(s>0&&x<r[i]){
				++x;
			}
			z+=y*x;
			y+=x;
		}
		wt(z);
	}
}
0