結果
| 問題 | No.818 Dinner time | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-04-20 10:54:40 | 
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 20 ms / 2,000 ms | 
| コード長 | 559 bytes | 
| コンパイル時間 | 287 ms | 
| コンパイル使用メモリ | 34,272 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-29 23:36:06 | 
| 合計ジャッジ時間 | 1,736 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 29 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         scanf("%lld %lld", &N, &M);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:12:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |         scanf("%lld %lld", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:17:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |                 scanf("%lld %lld", &a, &b);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include<stdio.h>
#include<algorithm>
using namespace std;
#define int long long
signed main(){
	int N, M, hoge[2][2] = {}, x, ans = 0, a, b, num;
	
	scanf("%lld %lld", &N, &M);
	scanf("%lld %lld", &a, &b);
	
	x =  max(b,a*(M-1)+max(a,b));
	
	for(int i = 1; i < N; i++){
		scanf("%lld %lld", &a, &b);
		
		num = max(a,b);
		
		hoge[(i+1)%2][1] =  max(b,a*(M-1)+num)+hoge[i%2][1];
		
		hoge[(i+1)%2][0] = max(hoge[i%2][0],hoge[i%2][1]) +num;
		
		ans = max(ans,max(hoge[(i+1)%2][0],hoge[(i+1)%2][1]));
	}
	
	ans += x;
	
	printf("%lld\n",ans);
	
	return 0;
}
            
            
            
        