UVa 957

a simple DC problem, binary search on each node and find the maximum one
/* UVas */
/*****************************************************************************/
int y, p, t;
int r, s, e;
vector<int> year;
int main(void) {
    while (cin>>y) {
        cin>>p;
        year.clear();
        for (int i=0; i<p; i++) {
            cin>>t;
            year.pb(t);
        }
        r=0;
        for (int i=0; i<p; i++) {
            int f=year[i]+y-1;
            vector<int>::iterator it=upper_bound(year.begin()+i, year.end(), f);
            int id=it-year.begin();
            if ((id-i)>r) {
                r=id-i;
                s=year[i];
                e=year[id-1];
            }
        }
        cout<<r<<" "<<s<<" "<<e<<endl;
    }
    return 0;
}
/*****************************************************************************/

No comments :

Post a Comment