結果

問題 No.999 てん vs. ほむ
ユーザー wakapaijazzwakapaijazz
提出日時 2020-03-01 03:19:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,537 bytes
コンパイル時間 2,714 ms
コンパイル使用メモリ 197,564 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 22:01:54
合計ジャッジ時間 3,980 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 31 ms
5,376 KB
testcase_22 AC 30 ms
5,376 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<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;
    vi a(m);
    vi b(n);
    rep(i,m) {
        cin >> a[i];
        if(i%2==1) b[(i-1)/2] = a[i]-a[i-1]; 
    }
    // 左からの累積和と右からの累積和
    vi 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, (ll)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