Public submissions
Source code of every submission to this problem in this contest will be visible for everyone since 2014-01-28 09:33:55.

SMPSEQ8 - Fun with Sequences (Act 6)

You are given a sequence of n integers S = s1, s2 ... sn and a sequence of m integers Q = q1, q2 ... qm. If q1 + q2 + ... + qm < s1 + s2 + ... + sn please print the sequence S and otherwise please print the sequence Q.

Input data specification

In the first line you are given one integer 2 <= n <= 100, and in the following line n integers:
-100 <= si <= 100.

In the third line you are given one integer 2 <= m <= 100, and in the following line m integers:
-100 <= qi <= 100.

Output data specification

The sequence of requested integers separated by spaces.

Example 1

Input:
5
-2 -1 0 1 4
6
-3 -2 -1 1 2 3

Output:
-2 -1 0 1 4

Example 2

Input:
5
-2 -1 0 1 2
6
-3 -2 -1 1 2 3

Output:
-3 -2 -1 1 2 3

Added by:kuszi
Date:2014-01-13
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Public source code since: 2014-01-28 09:33:55

hide comments
2019-04-18 17:06:59 kuszi
@2018-05-06 18:44:06 Please print the sequence Q

Last edit: 2019-04-18 17:07:27
2018-05-06 18:44:06
What am i suppose to do if both sum are equal?
2016-05-03 05:22:19
please remove getch() function and print new line at the end of main function.
2015-05-16 16:09:53 Almas
You are missing space in your first print.
2014-10-24 19:44:22 Amit Tapas
Showing wrong answer,Someone pls help

#include <stdio.h>
#include <conio.h>
int main()
{
int i,a,b[100],c,d[100],sum1=0,sum2=0;

scanf("%d",&a);
for(i=0;i<a;i++){scanf("%d",&b[i]);sum1=sum1+b[i];}
scanf("%d",&c);
for(i=0;i<c;i++){scanf("%d",&d[i]);sum2=sum2+d[i];}

if(sum1>sum2){for(i=0;i<a;i++){printf("%d",b[i]);}}
else{for(i=0;i<c;i++){printf("%d ",d[i]);}}

getch();
return 0;
}
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.