結果

問題 No.2501 Maximum Inversion Number
ユーザー tailstails
提出日時 2023-10-13 22:51:50
言語 cLay
(20240104-1)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 442 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 165,480 KB
実行使用メモリ 7,532 KB
最終ジャッジ日時 2023-10-13 22:51:59
合計ジャッジ時間 3,427 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 10 ms
4,444 KB
testcase_02 AC 25 ms
4,724 KB
testcase_03 AC 13 ms
4,840 KB
testcase_04 AC 15 ms
7,516 KB
testcase_05 AC 14 ms
7,524 KB
testcase_06 AC 16 ms
7,532 KB
testcase_07 AC 11 ms
5,432 KB
testcase_08 AC 13 ms
5,540 KB
testcase_09 AC 7 ms
5,960 KB
testcase_10 AC 11 ms
4,784 KB
testcase_11 AC 11 ms
5,244 KB
testcase_12 AC 10 ms
5,424 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 15 ms
7,488 KB
testcase_15 AC 9 ms
4,712 KB
testcase_16 AC 35 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==a&&x<r[i]){
				--s;
				++x;
			}
			z+=y*x;
			y+=x;
		}
		wt(z);
	}
}
0