GOODSET - Editorial

cakewalk
editorial
goodset
june17

#1

PROBLEM LINK:

Practice
Contest

Author: Praveen Dhinwa
Tester: Prateek Gupta
Editorialist: Oleksandr Kulkov

DIFFICULTY:

CAKEWALK

PREREQUISITES:

None

PROBLEM:

Output any set of distinct integers from 1 to 500 such that there are no three elements s_1+s_2=s_3.

EXPLANATION:

Since n is up to 100, one can just output integers from 500-n to 499. Sum of any two such integers is greater than 500 so requirements will be satisfied.

One other solution is to output the first n odd integers, i.e. 1, 3, 5, 7 and so on. Sum of any two odd numbers is even, which won’t be present in this set.

AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution will be updated soon.
Tester’s solution will be updated soon.
Editorialist’s solution can be found here.


#2

import random
def summ(l,n,a):
flag=0
if(a not in l):
for j in range(len(l)):
for k in range(len(l)):
if(l[j]+l[k]==a and j!=k):
flag=1
break
if(flag==0):
l.append(a)
return(l)
for i in range(int(input())):
n=int(input())
l=[]
while(len(l)!=n):
a=random.randint(1,500)
summ(l,n,a)
print(*l)
#what’s wrong in this code?