我收到运行时错误。 [英] I am getting runtime error.

查看:48
本文介绍了我收到运行时错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将获得两个阵列A和B,每个阵列包含N个数字。您需要从A中精确选择一个数字,并从B中选择一个数字,这样两个所选数字的索引不相同,并且所选择的两个值的总和最小。形式上,如果您选择A中的ith元素,其值为x,而B中的第j个元素的值为y,则需要最小化(x + y)的值,使得i不等于j。

你的目标是找到这个最小值。





输入:

第一行输入包含表示测试用例的整数t。每个测试用例的第一行包含一个整数N,表示两个数组的大小。然后,接下来的两行中的每一行都包含N个空格分隔的整数,分别表示数组A []和B []的值。





输出:

打印在问题陈述中提到的条件下可以获得的最小金额。如果不可能打印-1没有引号。





限制条件:

1< = T< = 30

1< = N< = 100000

1< =数组元素< = 100000



例如:

输入:

1

5 br />
5 4 3 2 1

1 2 3 4 5

输出:

2



说明:

通过选择第一个数组的最后一个索引处的数字即第一个数组的第5个元素(1)和第二个数组的第一个索引来获得最小总和数组,即第二个数组的第一个元素(1)。



Sum = 1 + 1 = 2,因为它们的索引不同但总和最小。



我尝试了什么:



You are given two arrays A and B each containing N numbers. You need to choose exactly one number from A and exactly one number from B such that the index of the two chosen numbers is not same and the sum of the 2 chosen values is minimum. Formally, if you chose ith element from A whose value is x and jth element from B whose value is y, you need to minimize the value of (x+y) such that i is not equal to j.
Your objective is to find this minimum value.


Input:
The first line of input contains an integer denoting the test cases,t. The first line of each test case contains an integer N denoting the size of two arrays. Then each of the next two lines contains N space separated integers denoting values of the array A[] and B[] respectively.


Output:
Print the minimum sum which can be obtained under the conditions mentioned in the problem statement.If not possible print "-1" without quotes.


Constraints:
1<=T<=30
1<= N <=100000
1< =Array elements < =100000

Example:
Input:
1
5
5 4 3 2 1
1 2 3 4 5
Output:
2

Explanation:
Minimum sum will be obtained by choosing number at the last index of first array i.e. 5th element of the first array(1) and first index of the second array ie first element of second array (1).

Sum=1+1=2 as their indexes are different but sum is minimum.

What I have tried:

#include
int main()
{
int t,i,j,k,min=0;
//# of test cases
scanf("%d",&t);

struct testcase
  {
  	int sizeOfArray;
  	int a[10];
  	int b[10];
  	int ans;
  	
  };
  
 struct testcase tc[t];            //array of structures, size t 
  
  for(i=0;i<t;i++)
  {
  	scanf("%d",&tc[i].sizeOfArray);  //entering size of a and b
  	
  	 for(j=0;j<tc[i].sizeOfArray;j++)   //entering elements of a
  	 {
  	 	
  	 	scanf("%d",&(tc[i].a[j]));
	 }
  	
  	for(j=0;j<tc[i].sizeOfArray;j++)   //entering elements of b
  	 {
  	 	
  	 	scanf("%d",&tc[i].b[j]);
	 }  		
  }
  

int no=0;
for(k=0;k<t;k++)
{
	
    min=	tc[k].a[0]+tc[k].b[1];
	for(i=0;i<tc[k].sizeOfArray;i++)
	{
	 
	
		for(j=0;(j<tc[k].sizeOfArray);j++)
		 { 
		 if((tc[k].a[i]+tc[k].b[j]<min)&&(j!=i))
		 	{
		 	 
		 		min=tc[k].a[i]+tc[k].b[j];
			}
		 }
	}
	
	tc[k].ans=min;
	printf("%d\n",min);

}


return 0;
	
}







//因为这会给我正确的结果系统但我在提交此代码时遇到运行时错误




//As this is giving correct results on my system but I am getting runtime error while //submitting this code

推荐答案

引用:

//因为这会在我的系统上给出正确的结果,但是我在//提交此代码时遇到运行时错误

//As this is giving correct results on my system but I am getting runtime error while //submitting this code

问题可能是您的提交在阵列A和B中使用了10个以上的值进行了测试。 br />
PS:下次:尝试说出错误信息。

The problem is probably that your submission is tested with more that 10 values in array A and B.
PS: next time: try to state the error message.

引用:

否我用不到10个元素测试,它给了我正确的结果,但是当我在geeksforgeeks上提交它时,它给了我

No I was testing with less then 10 elements, it was giving me correct results, but when I submit it on geeksforgeeks, it gives me

是的你,但是他们!

他们有多少元素用过?

Yes you, but them!
How many elements did they used ?


这篇关于我收到运行时错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆