結果

問題 No.1687 What the Heck?
ユーザー noya2
提出日時 2025-03-06 16:54:43
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 3,399 ms
コンパイル使用メモリ 280,972 KB
実行使用メモリ 8,604 KB
最終ジャッジ日時 2025-03-06 16:54:49
合計ジャッジ時間 5,834 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using pll = pair<ll,ll>;

int main(){
	ll n; cin >> n;
	vector<pll> ar(n);
	for (int i = 0; i < n; i++){
		ll c; cin >> c;
	    ar[i] = pll(-c,ll(i+1));
	}
	sort(ar.begin(),ar.end());
	if (n == 1){
	    assert(ar[0].first == -1);
	    cout << 0 << endl;
	    return 0;
	}
	ll f = n * (n + 1) / 2;
	ll ima = 2 * ar[0].second;
	ll mi = ima;
	for (int i = 0; i < n-1; i++){
	    ima = ima - ar[i].second + 2 * ar[i+1].second;
	    if (i == n-2) ima -= ar[i+1].second;
	    mi = min(mi,ima);
	}
	for (int i = 0; i < n; i++){
	    assert(n+ar[i].first == i);
	}
	cout << f - mi << endl;
	return 0;
}
0