結果

問題 No.999 てん vs. ほむ
ユーザー wakapaijazzwakapaijazz
提出日時 2020-03-01 03:27:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 1,582 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 197,884 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-21 22:02:11
合計ジャッジ時間 3,668 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 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 29 ms
6,784 KB
testcase_10 AC 10 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 15 ms
5,376 KB
testcase_13 AC 32 ms
7,168 KB
testcase_14 AC 32 ms
7,168 KB
testcase_15 AC 32 ms
7,168 KB
testcase_16 AC 33 ms
7,168 KB
testcase_17 AC 22 ms
6,912 KB
testcase_18 AC 22 ms
6,784 KB
testcase_19 AC 22 ms
6,912 KB
testcase_20 AC 23 ms
6,784 KB
testcase_21 AC 32 ms
6,912 KB
testcase_22 AC 31 ms
6,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

/*** chmax, chmin ***/
// a < b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b; 
		return true;
	}
	return false;
}
// a > b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b; 
		return true;
	}
	return false;
}
/*** chmax, chmin ここまで ***/

void Main()
{
    int n;
    cin >> n;
    int m = 2*n;
    vll a(m);
    vll b(n);
    rep(i,m) {
        cin >> a[i];
        if(i%2==1) b[(i-1)/2] = a[i]-a[i-1]; 
    }
    // 左からの累積和と右からの累積和
    vll suml(n), sumr(n);
    suml[0] = -b[0];
    sumr[n-1] = b[n-1];
    rep(i,n-1) suml[i+1] = suml[i]-b[i+1];
    rep3rev(i,n-2,0) sumr[i] = sumr[i+1]+ b[i];  
    
    //rep(i,n) cout << i << ": " << suml[i] << " " << sumr[i] << endl;
    ll ans = max(suml[n-1], sumr[0]);
    rep(i,n-1) chmax(ans, suml[i]+sumr[i+1]);
    cout << ans << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}
0