結果

問題 No.2501 Maximum Inversion Number
ユーザー tailstails
提出日時 2023-10-13 22:50:25
言語 cLay
(20240104-1)
結果
WA  
実行時間 -
コード長 436 bytes
コンパイル時間 2,986 ms
コンパイル使用メモリ 165,208 KB
実行使用メモリ 7,688 KB
最終ジャッジ日時 2023-10-13 22:50:32
合計ジャッジ時間 4,423 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 AC 14 ms
5,336 KB
testcase_09 AC 7 ms
5,988 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 34 ms
4,832 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]){
				--s;
				++x;
			}
			z+=y*x;
			y+=x;
		}
		wt(z);
	}
}
0