close

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2098

 

#include<cstdio>

#include<iostream>

#include<algorithm>

using namespace std;

main(){

    //t: test case

    //n: number of stone

    //d: river width

    int t, n, d, b, maxnum;

    int i, j, k;

    int stone[220];

    char ch;

    cin >> t;

    for (i = 0; t>0; t--) {

        cin >> n >> d;

        stone[0] = 0;

        stone[1] = d;

        for (j = 0, k = 2;j < n; j++){

            cin >> ch;

            cin.ignore();

            cin >> b;

            stone[k] = b;

            k++;

            if (ch == 'B'){

                stone[k] = b;

                k++;

            }

        }

        sort(stone, stone+k);

        maxnum = 0;

        if (n == 0)

            maxnum = d;

        else{

            for (j = 2; j < k; j += 2)

                maxnum = max(maxnum, stone[j] - stone[j - 2]);

            for (j = 3; j < k; j += 2)

                maxnum = max(maxnum, stone[j] - stone[j - 2]);

        }

        cout << "Case " << ++i << ": " << maxnum << endl;

    }

}

arrow
arrow
    全站熱搜

    楓綺 發表在 痞客邦 留言(0) 人氣()