## 10013 - Super long sums

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10013 - Super Long Sums

There is a blank line between output blocks.
Check input and AC output for thousands of problems on uDebug!
20717TZ
New poster
Posts: 33
Joined: Tue Apr 27, 2004 7:41 pm
Location: Santa Clara / Mountain View, CA, USA
Contact:

### Re:

tenshi wrote:check this case:

1

4
0 9
0 9
0 9
1 9
This is an invalid input, because
Each of the two given integers is not less than 1, and the length of their sum does not exceed M.
I Believe I Can - leestime.com
sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

### Re: 10013 - Super long sums

#include <iostream>

using namespace std;

int main()
{
long long int a,b,c,num[10000],num1[10000],i=0,sum=0,k=0,res[10000];
cin>>a;
while(a--)
{
cin>>b;
while(b--)
{
cin>>num;
cin>>num1;
i++;
}
for(int j=i-1;j>-1;j--)
{
c=num[j]+num1[j];
if(c>9 && j!=0)
{
res[k]=c-10;
k++;
num[j-1]=num[j-1]+1;
}
else
{
res[k]=c;
k++;
}
}
for(int j=k-1;j>-1;j--)
cout<<res[j];
cout<<endl;
if(a!=0)
cout<<endl;
sum=0;i=0,k=0;

}
return 0;
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10013 - Super long sums

1<=M<=1000000
Check input and AC output for thousands of problems on uDebug!
mgavin2
New poster
Posts: 43
Joined: Sat Jul 28, 2012 6:29 pm

### Re: 10013 - Super long sums

is using java BigInteger TLE? I can't seem to optimize a java solution enough to pass the time limit.
all that matters is AC
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10013 - Super long sums

Try solving it without using BigInteger, just sum and print using int arrays.
Check input and AC output for thousands of problems on uDebug!
axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

### Re: 10013 - Super long sums

I getting WA...

Code: Select all

``````#include<iostream>
//#include<cstdio>
using namespace std;

int main()
{
//freopen("in.txt","r",stdin);
int n,m,carry,j;
short temp;
cin>>n;
for(int i=0;i<n;i++)
{
if(i) cout<<endl;
carry=0;
cin>>m;
short int a[m],b[m],ans[m];
for(j=m-1;j>=0;j--)
cin>>a[j]>>b[j];
for(j=0;j<m;j++)
{
temp=a[j]+b[j];
ans[j]=temp%10+carry;
carry=temp>9;
}
for(j=m-1;j>=0;j--)
cout<<ans[j];
cout<<endl;
}
return 0;
}
``````
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 10013 - Super long sums

Input

Code: Select all

``````1

3
1 2
7 2
2 8``````
Acc Output

Code: Select all

``````400
``````
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
axelblaze
New poster
Posts: 34
Joined: Mon Jun 23, 2014 7:45 pm

### Re: 10013 - Super long sums

Thanks I got AC.. It was a silly mistake though.. I wasn't carefull..
Thanks again..
ashek.rahman
New poster
Posts: 8
Joined: Mon Mar 10, 2014 8:18 am

### Re: 10013 - Super long sums

Removed. Solved.
nasim.ruet
New poster
Posts: 10
Joined: Sat Sep 06, 2014 12:44 pm

### Re: 10013 - Super long sums

Code: Select all

``````import java.util.Scanner;

public class Main {

private static Scanner scanner;

public static void main(String[] args) {
scanner = new Scanner(System.in);
int n, m;
short temp, carry = 0;
char ch;
short[] firstAra = new short[1000005];
short[] secondAra = new short[1000005];

while (scanner.hasNext()) {
n = scanner.nextInt();
for (int j = 0; j < n; j++) {
m = scanner.nextInt();
for (int k = 0; k < m; k++) {
firstAra[k] = scanner.nextShort();
secondAra[k] = scanner.nextShort();
}
String string = "";
carry = 0;
for (int k = m - 1; k >= 0; k--) {
temp = (short) (firstAra[k] + secondAra[k] + carry);
if (temp > 9) {
temp = (short) (temp % 10);
carry = 1;
} else {
carry = 0;
}
ch = (char) temp;
ch += 48;
string = string + ch;
}
if (carry == 1) {
string = string + 1;
}
StringBuffer buffer = new StringBuffer(string);
System.out.println(buffer.reverse() + "\n");
}

}

}

}

``````
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10013 - Super long sums

Try using BufferedReader and BufferedWriter.
Check input and AC output for thousands of problems on uDebug!
Karkat_Vantas
New poster
Posts: 4
Joined: Thu Aug 21, 2014 2:59 am

### Re: 10013 - Super long sums

I don't understand why my code is giving me a submission error. It seems to work on the sample cases and what I can find in this forum. Can someone please explain why this is occuring? Thank you for your help.

Code: Select all

``````import java.math.BigInteger;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int trials = in.nextInt();
StringBuilder a;
StringBuilder b;
int l;
for (int tr = 1; tr <= trials; tr++) {
a=new StringBuilder("");
b=new StringBuilder("");
l=in.nextInt();
for(int j=0;j<l;j++)
{
a=a.append(in.next());
b=b.append(in.next());
}
BigInteger z = new BigInteger(a.toString());
BigInteger x = new BigInteger(b.toString());
if(tr!=trials)
System.out.println("");
}

}
}``````
lighted
Guru
Posts: 587
Joined: Wed Jun 11, 2014 9:56 pm
Location: Kyrgyzstan, Bishkek

### Re: 10013 - Super long sums

Sometimes it happens. Try it again. Judge gives TLE for your code.
brianfry713 wrote:Try using BufferedReader and BufferedWriter.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
bgcsaif
New poster
Posts: 38
Joined: Mon Sep 29, 2014 4:03 pm

### Re: 10013 - Super long sums

it is said that "each of the two given integers is not less than 1"..... but in sample input there is given 0 as one of the integers..... is there anything i understood wrong???