結果
問題 | No.1199 お菓子配り-2 |
ユーザー |
|
提出日時 | 2020-09-06 21:40:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 489 ms / 1,000 ms |
コード長 | 761 bytes |
コンパイル時間 | 1,220 ms |
コンパイル使用メモリ | 108,016 KB |
最終ジャッジ日時 | 2025-01-14 08:02:59 |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#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;}}std::vector<long long int> memo(2, LLONG_MIN >> 1); memo[0] = 0;for (const auto h : happiness) {const auto odd = memo[0];const auto even = memo[1];memo[0] = std::max(odd, even - h);memo[1] = std::max(even, odd + h);}std::cout << *std::max_element(memo.begin(), memo.end()) << '\n';}