結果
問題 | No.818 Dinner time |
ユーザー |
![]() |
提出日時 | 2020-12-08 17:45:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 28 ms / 2,000 ms |
コード長 | 597 bytes |
コンパイル時間 | 2,140 ms |
コンパイル使用メモリ | 199,764 KB |
最終ジャッジ日時 | 2025-01-16 19:47:47 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 29 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | rep(i,N)scanf("%lld %lld",&A[i],&B[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000000000000 int main(){ int N,M; cin>>N>>M; vector<long long> A(N),B(N); rep(i,N)scanf("%lld %lld",&A[i],&B[i]); vector dp(N,vector<long long>(2,-Inf)); dp[0][0] = max({B[0],A[0]*M,A[0]*(M-1)+B[0]}); for(int i=1;i<N;i++){ dp[i][0] = dp[i-1][0] + max({B[i],A[i]*M,A[i]*(M-1)+B[i]}); dp[i][1] = max(dp[i-1][0],dp[i-1][1]) + max(A[i],B[i]); } long long ans = -Inf; rep(i,N){ rep(j,2){ ans = max(ans,dp[i][j]); } } cout<<ans<<endl; return 0; }