N = int(input())
if N == 1:
exit(0)
bacteria = [0] * N
for i in range(0, N):
bacteria[i] = int(input())
prefix_sum = [bacteria[0]] * N
for i in range(1, N):
prefix_sum[i] = prefix_sum[i - 1] + bacteria[i]
ans = [0] * N
if bacteria[N-1] > bacteria[0]:
ans[N - 1] = 1
for i in reversed(range(2, N)):
if ans[i] == 1:
prev = i - 1
if prefix_sum[prev] > bacteria[i] and bacteria[0] < bacteria[prev]:
ans[prev] = 1
for i in range(N):
print(ans[i])
Объяснение:
g++
N = int(input())
if N == 1:
exit(0)
bacteria = [0] * N
for i in range(0, N):
bacteria[i] = int(input())
prefix_sum = [bacteria[0]] * N
for i in range(1, N):
prefix_sum[i] = prefix_sum[i - 1] + bacteria[i]
ans = [0] * N
if bacteria[N-1] > bacteria[0]:
ans[N - 1] = 1
for i in reversed(range(2, N)):
if ans[i] == 1:
prev = i - 1
if prefix_sum[prev] > bacteria[i] and bacteria[0] < bacteria[prev]:
ans[prev] = 1
for i in range(N):
print(ans[i])
Объяснение:
g++-GNU C++ 8.3.1
public class Test
{
public static int Main()
{
Random rnd=new Random(DateTime.Now.Millisecond); // иниц. датчика
int n=Convert.ToInt32(Console.ReadLine());
double[] Arr=new double[n];
double e, max=0;
for(int i=0;i<Arr.Length; i++)
{
Arr[i]=(int)(rnd.Next(1,99));
Console.Write(Arr[i]+" ");
e=Math.Abs(Arr[i]);
if(e>max) max=e;
}
Console.WriteLine("\nmax={0:f1}",max);
return 0;
}
}
Пример
15
56 9 1 94 34 42 46 71 2 27 91 37 54 31 66
max=94.0