結果

問題 No.561 東京と京都
ユーザー BucchimanBucchiman
提出日時 2020-04-04 19:12:00
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 964 bytes
コンパイル時間 589 ms
コンパイル使用メモリ 28,020 KB
実行使用メモリ 6,052 KB
最終ジャッジ日時 2023-09-16 06:06:07
合計ジャッジ時間 4,543 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 AC 0 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
 * FileName:     no_561_tokyo_kyoto
 * CreatedDate:  2020-04-04 10:48:11 +0900
 * LastModified: 2020-04-04 19:11:10 +0900
 */

#include <stdio.h>
long int max(long int s, long int t){
    if(s>t){ return s; }
    else{ return t; }
}
long int dp( int i, int N, long int D, long int T[], long int K[], int bi){
    if(i==N){
        return 0;
    }
    else if( bi==0 ){
        long int box_0 = dp(i+1,N,D,T,K,0)+T[i];
        long int box_1 = dp(i+1,N,D,T,K,1)+K[i]-D;
        return max(box_0,box_1);
    }
    else{
        long int box_0 = dp(i+1,N,D,T,K,0)+T[i]-D;
        long int box_1 = dp(i+1,N,D,T,K,1)+K[i];
        return max(box_0,box_1);
    }
}
int main(void){
    int N;
    long int D;
    scanf("%d %ld",&N,&D);
    long int T[N],K[N];
    for(int i=0;i<N;i++){
        scanf("%ld %ld",&T[i], &K[i]);
    }
    long int tmp_0 = dp(0,N,D,T,K,0);
    long int tmp_1 = dp(0,N,D,T,K,1)-D;
    
    printf("%ld\n",max(tmp_0,tmp_1));
    return 0;
}
0