結果

問題 No.561 東京と京都
ユーザー BucchimanBucchiman
提出日時 2020-04-05 12:49:22
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 1,188 bytes
コンパイル時間 513 ms
コンパイル使用メモリ 28,468 KB
実行使用メモリ 10,536 KB
最終ジャッジ日時 2023-09-16 06:35:11
合計ジャッジ時間 7,802 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
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 20:55:32 +0900
 */

#include <stdio.h>
#include <unistd.h>
int second=1;
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){
    sleep(second);
    if(i==N){
        return 0;
    }
    else{
        long int box_0,box_1;
        if( bi==0 ){
            box_0 = dp(i+1,N,D,T,K,0)+T[i];
            box_1 = dp(i+1,N,D,T,K,1)+K[i]-D;
            printf("%d:%d{%ld,%ld}\n",i,bi,box_0,box_1);
            return max(box_0,box_1);
        }
        else if( bi==1 ){
            box_0 = dp(i+1,N,D,T,K,0)+T[i]-D;
            box_1 = dp(i+1,N,D,T,K,1)+K[i];
            printf("%d:%d{%ld,%ld}\n",i,bi,box_0,box_1);
            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