Codeforces 427A

#include <stdio.h>

int main()
{
	int min=0;
	int num;
	int temp;
	int sum=0;
	scanf("%d", &num);
	while(num--)
	{
		scanf("%d", &temp);
		sum+=temp;
		if((sum<0)&&(sum<min))
			min=sum;
	}
	printf("%d\n", min*(-1));
	return 0;
}

  @ Setting a variable minimum value min is initialized to 0, if the value of the variable sum is less than 0, it is compared with the variable min, if the variable is smaller than min, min is the value assigned to a sum of the value of the variable then the variable. Such code segments that perform the last saved variable min is the minimum value of the whole process, which can be output is multiplied by -1.

Guess you like

Origin www.cnblogs.com/commario/p/11923891.html