Question one hundred and sixteen: number of dominant values

Source: Internet
Author: User

[Plain] Description
 
We know that f [] and g [] are two integer arrays, and the elements are sorted in ascending order. Please write a program to calculate the logarithm of f [] greater than the element in g. In other words, f [0] is bigger than how many elements in g [], and f [1] is bigger than how many elements in g []. The sum of these values is the answer.
For example, if f [] contains 1, 3, 5, 7, 9, and g [] contains 2, 3, 4, 7, and 8.
So:
F [0] is smaller than all elements in g;
F [1] is larger than g [0;
F [2] is larger than g [0], g [1], and g [2;
F [3] is larger than g [0], g [1], and g [2;
F [4] is larger than g [0], g [1], g [2], g [3], and g [4;
So the answer is 0 + 1 + 3 + 3 + 5 = 12.
 
Input
 
The first behavior is two integers, m, n (1 ≤ m, n ≤ 1000), representing the length of the array f [], g [], respectively.
The second row has m elements, which are arrays f [].
The third row has n elements, which are array g [].
 
Output
 
Output Control Value.
 
Sample Input
 
 
5 5
1 3 5 7 9
2 3 4 7 8
 
Sample Output
 
 
12

Description

We know that f [] and g [] are two integer arrays, and the elements are sorted in ascending order. Please write a program to calculate the logarithm of f [] greater than the element in g. In other words, f [0] is bigger than how many elements in g [], and f [1] is bigger than how many elements in g []. The sum of these values is the answer.
For example, if f [] contains 1, 3, 5, 7, 9, and g [] contains 2, 3, 4, 7, and 8.
So:
F [0] is smaller than all elements in g;
F [1] is larger than g [0;
F [2] is larger than g [0], g [1], and g [2;
F [3] is larger than g [0], g [1], and g [2;
F [4] is larger than g [0], g [1], g [2], g [3], and g [4;
So the answer is 0 + 1 + 3 + 3 + 5 = 12.

Input

The first behavior is two integers, m, n (1 ≤ m, n ≤ 1000), representing the length of the array f [], g [], respectively.
The second row has m elements, which are arrays f [].
The third row has n elements, which are array g [].

Output

Output Control Value.

Sample Input


5 5
1 3 5 7 9
2 3 4 7 8

Sample Output


12


[Plain] # include <stdio. h>
 
Int main ()
{
Int I;
Int j;
Int n;
Int m;
Int sum;
Int f [1001];
Int g [1001];

Scanf ("% d", & n, & m );
Sum = 0;

For (I = 0; I <n; I ++)
{
Scanf ("% d", & f [I]);
}
For (j = 0; j <m; j ++)
{
Scanf ("% d", & g [j]);
}
 
For (I = 0; I <n; I ++)
{
For (j = 0; j <m; j ++)
{
If (f [I]> g [j])
{
Sum ++;
}
Else
{
Break;
}
}
}
 
Printf ("% d \ n", sum );
 
Return 0;
}

# Include <stdio. h>

Int main ()
{
Int I;
Int j;
Int n;
Int m;
Int sum;
Int f [1001];
Int g [1001];

Scanf ("% d", & n, & m );
Sum = 0;

For (I = 0; I <n; I ++)
{
Scanf ("% d", & f [I]);
}
For (j = 0; j <m; j ++)
{
Scanf ("% d", & g [j]);
}

For (I = 0; I <n; I ++)
{
For (j = 0; j <m; j ++)
{
If (f [I]> g [j])
{
Sum ++;
}
Else
{
Break;
}
}
}

Printf ("% d \ n", sum );

Return 0;
}

 

 
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.