結果

問題 No.999 てん vs. ほむ
ユーザー wakapaijazzwakapaijazz
提出日時 2020-03-01 03:23:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,639 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 198,148 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-21 22:02:07
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 WA -
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 27 ms
6,944 KB
testcase_10 AC 10 ms
6,940 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 13 ms
6,944 KB
testcase_13 AC 29 ms
7,040 KB
testcase_14 AC 29 ms
7,040 KB
testcase_15 AC 30 ms
7,168 KB
testcase_16 AC 29 ms
7,168 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 29 ms
7,040 KB
testcase_22 AC 27 ms
7,040 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]; 
    }
    if(n==1) {
        cout << max(b[0], -b[0]) << endl;
        return;
    }
    // 左からの累積和と右からの累積和
    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 = 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