結果

問題 No.999 てん vs. ほむ
ユーザー KKT89KKT89
提出日時 2020-02-28 21:31:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 547 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 82,284 KB
実行使用メモリ 6,332 KB
最終ジャッジ日時 2023-08-03 19:38:33
合計ジャッジ時間 2,094 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 24 ms
5,932 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 12 ms
4,448 KB
testcase_13 AC 27 ms
6,224 KB
testcase_14 AC 27 ms
6,164 KB
testcase_15 AC 27 ms
6,288 KB
testcase_16 AC 26 ms
6,196 KB
testcase_17 AC 20 ms
5,904 KB
testcase_18 AC 19 ms
5,888 KB
testcase_19 AC 20 ms
6,180 KB
testcase_20 AC 20 ms
6,012 KB
testcase_21 AC 27 ms
6,332 KB
testcase_22 AC 26 ms
5,956 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]);
	}
	ans=max(ans,cnt2[0]);
	cout << ans << endl;
}
0