結果

問題 No.1687 What the Heck?
ユーザー forest3
提出日時 2021-09-26 15:49:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 1,909 ms
コンパイル使用メモリ 175,440 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-07-05 15:38:30
合計ジャッジ時間 3,129 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
	int N;
	cin >> N;
	vector<int> a( N );
	for( int i = 0; i < N; i++ ) cin >> a[i];

	typedef pair<int, int> P;
	vector<P> p( N );
	for( int i = 0; i < N; i++ ) p[i] = P( a[i], i + 1 );
	sort( p.begin(), p.end() );
	vector<long long> acc( N + 1 );
	for( int i = 0; i < N; i++ ) {
		acc[i + 1] = acc[i] + p[i].second;
	}
	long long ans = 0;
	for( int i = N - 1; i >= 0; i-- ) {
		long long a = -p[i].second;
		if( i - 1 >= 0 ) a += acc[i]; 
		ans = max( ans, max( a, 0LL ) );
	}

	cout << ans << endl;
}
0