二次联通门 : luogu P1007 独木桥
/* luogu P1007 独木桥 模拟 */ #include <cstdio> inline int min (int a, int b) { return a < b ? a : b; } inline int max (int a, int b) { return a > b ? a : b; } void read (int &now) { register char word = getchar (); for (now = 0; word < '0' || word > '9'; word = getchar ()); for (; word >= '0' && word <= '9'; now = now * 10 + word - '0', word = getchar ()); } int main (int argc, char *argv[]) { int L, N; read (L); read (N); int x, y; if (!N) { printf ("0 0"); return 0; } int Max_Answer = -1, Min_Answer = -1; for (int i = 1; i <= N; i ++) { read (x); Max_Answer = max (Max_Answer, max (L - x + 1, x)); Min_Answer = max (Min_Answer, min (L - x + 1, x)); } printf ("%d %d", Min_Answer, Max_Answer); return 0; }