POJ Ants

#include <iostream>

using namespace std;

#define maxn 1000000+10

int pos[maxn], L, n, T;
int mi, ma;

int main()
{
    cin>>T;
    while(T--)
    {
        cin>>L>>n;
        for(int i=0; i<n; i++)
        cin>>pos[i];
        int t = (L+1)/2;
        mi = -1;
        ma = -1;
        for(int i=0; i<n; i++)
        {
            if(pos[i] <= t)
            {
                mi = max(mi, pos[i]);
                ma = max(ma, L-pos[i]);
            }
            else
            {
                mi = max(mi, L-pos[i]);
                ma = max(ma, pos[i]);
            }
        }

        cout<<mi<<" "<<ma<<endl;
    }
    return 0;
}

你可能感兴趣的:(ACM,poj)