結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 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 AC 41 ms
4,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

ll@t;
rep(t){
	ll@n,@m,@l[n],@r[n];
	if(sum(l(n))>m||sum(r(n))<m){
		wt(-1);
	}else{
		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;
			}
		}
		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