結果
問題 |
No.1199 お菓子配り-2
|
ユーザー |
![]() |
提出日時 | 2020-08-29 12:48:48 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 436 ms / 1,000 ms |
コード長 | 1,161 bytes |
コンパイル時間 | 1,724 ms |
コンパイル使用メモリ | 85,188 KB |
実行使用メモリ | 11,264 KB |
最終ジャッジ日時 | 2024-11-14 05:36:31 |
合計ジャッジ時間 | 16,818 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include<iostream> #include<iomanip> #include<cmath> #include<string> #include<cstring> #include<vector> #include<list> #include<algorithm> #include<map> #include<set> #include<queue> #include<stack> using namespace std; typedef long long ll; #define fi first #define se second #define mp make_pair #define rep(i, n) for(int i=0;i<n;++i) #define rrep(i, n) for(int i=n;i>=0;--i) const int inf=1e9+7; const ll mod=1e9+7; const ll mod1=998244353; const ll big=1e18; const double PI=2*asin(1); int main() { int N, M; cin>>N>>M; ll tmpA[N][M]; for(int i=0;i<N;++i) { for(int j=0;j<M;++j) { cin>>tmpA[i][j]; } } vector<ll> A(N); for(int i=0;i<N;++i) { A[i] = 0; for(int j=0;j<M;++j) { A[i] += tmpA[i][j]; } } if(N==1) { cout<<A[0]<<endl; return 0; } bool up; ll ans = 0; if(A[0]<=A[1]) up = true; else { up = false; ans += A[0]; } for(int i=1;i<N;++i) { if(up) { if(A[i]>A[i+1]) { up = false; ans += A[i]; } } else { if(A[i]<A[i+1]) { up = true; ans -= A[i]; } } } if(up) ans += A[N-1]; cout<<ans<<endl; }