結果

問題 No.1687 What the Heck?
ユーザー forest3forest3
提出日時 2021-09-26 15:49:44
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 174,528 KB
実行使用メモリ 6,980 KB
最終ジャッジ日時 2023-09-19 02:53:58
合計ジャッジ時間 3,599 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 27 ms
4,376 KB
testcase_08 AC 38 ms
4,852 KB
testcase_09 AC 27 ms
4,376 KB
testcase_10 AC 19 ms
4,376 KB
testcase_11 AC 19 ms
4,380 KB
testcase_12 AC 78 ms
6,940 KB
testcase_13 AC 78 ms
6,976 KB
testcase_14 AC 78 ms
6,932 KB
testcase_15 AC 78 ms
6,936 KB
testcase_16 AC 78 ms
6,980 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 78 ms
6,932 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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