結果

問題 No.1199 お菓子配り-2
ユーザー yudedako
提出日時 2020-09-06 21:44:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 499 ms / 1,000 ms
コード長 695 bytes
コンパイル時間 1,228 ms
コンパイル使用メモリ 106,284 KB
最終ジャッジ日時 2025-01-14 08:03:35
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
#include <numeric>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <cassert>
#include <stack>
#include <climits>

int main() {
	int n, m; std::cin >> n >> m;
	std::vector<long long int> happiness(n, 0);
	for (auto& h : happiness) {
		for (auto i = 0; i < m; ++i) {
			long long int a; std::cin >> a;
			h += a;
		}
	}
	long long int odd{ 0 }, even{ LLONG_MIN >> 1};
	for (const auto h : happiness) {
		const auto o = std::max(odd, even - h);
		const auto e = std::max(even, odd + h);
		odd = o;
		even = e;
	}
	std::cout << std::max(odd, even) << '\n';
}
0