10分求助
  • 板块P1007 独木桥
  • 楼主迟陌
  • 当前回复3
  • 已保存回复3
  • 发布时间2023/7/29 16:56
  • 上次更新2023/11/3 07:02:34
查看原帖
10分求助
160870
迟陌楼主2023/7/29 16:56

本地跑了几组数据都没问题,但为啥一提交就WA了呢 求大佬指导

#include<stdio.h>
#include<math.h>
using namespace std;
int max(int x, int y)
{
	if (x >= y)
		return x;
	else
		return y;
}
int min(int x, int y)
{
	if (x <= y)
		return x;
	else
		return y;
}
int a[1000001];
int read()
{
	char c = getchar();
	int s = 0;
	while (c >= '0' && c <= '9')
	{
		s = s * 10 + c - '0';
		c = getchar();
	}
	return s;
}
int main()
{
	int l, n;
	l = read();
	n = read();
	for (int i = 1; i <= n; i++)
		a[i] = read();
	if (!n)
	{
		printf("0 0");
		return 0;
	}

	int mint=-1,maxt=-1;
	for (int i = 1; i <= n; i++)
	{
		mint = max(min(l + 1 - a[i], a[i]),mint);
		maxt = max(max(l + 1 - a[i], a[i]), maxt);
	}
	printf("%d %d", mint, maxt);
	return 0;
}
2023/7/29 16:56
加载中...