結果

問題 No.999 てん vs. ほむ
ユーザー KKT89KKT89
提出日時 2020-02-28 21:28:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 523 bytes
コンパイル時間 699 ms
コンパイル使用メモリ 82,848 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-21 17:51:43
合計ジャッジ時間 1,993 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 27 ms
6,016 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 13 ms
5,376 KB
testcase_13 AC 31 ms
6,528 KB
testcase_14 AC 30 ms
6,528 KB
testcase_15 AC 29 ms
6,400 KB
testcase_16 AC 31 ms
6,528 KB
testcase_17 WA -
testcase_18 AC 21 ms
6,016 KB
testcase_19 WA -
testcase_20 AC 22 ms
6,016 KB
testcase_21 AC 30 ms
6,272 KB
testcase_22 AC 29 ms
6,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(2*n);
	for(int i=0;i<2*n;i++){
		cin >> a[i];
	}
	vector<ll> cnt(n+1,0),cnt2(n+1,0);
	for(int i=0;i<n;i++){
		cnt[i+1]=a[i*2]-a[i*2+1]+cnt[i];
	}
	for(int i=n-1;i>0;i--){
		cnt2[i]=cnt2[i+1]+a[i*2+1]-a[i*2];
	}
	ll ans=cnt[n];
	for(int i=0;i<n;i++){
		ans=max(ans,cnt[i]+cnt2[i]);
	}
	cout << ans << endl;
}
0