The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple - B King of Karaoke

King of Karaoke

Time Limit:  1 Second       Memory Limit:  65536 KB

It's Karaoke time! DreamGrid is performing the song Powder Snow in the game King of Karaoke. The song performed by DreamGrid can be considered as an integer sequence , and the standard version of the song can be considered as another integer sequence . The score is the number of integers  satisfying  and .

As a good tuner, DreamGrid can choose an integer  (can be positive, 0, or negative) as his tune and add  to every element in . Can you help him maximize his score by choosing a proper tune?

Input

There are multiple test cases. The first line of the input contains an integer  (about 100), indicating the number of test cases. For each test case:

The first line contains one integer  (), indicating the length of the sequences  and .

The second line contains  integers  (), indicating the song performed by DreamGrid.

The third line contains  integers  (), indicating the standard version of the song.

It's guaranteed that at most 5 test cases have .

Output

For each test case output one line containing one integer, indicating the maximum possible score.

Sample Input

2
4
1 2 3 4
2 3 4 6
5
-5 -4 -3 -2 -1
5 4 3 2 1

Sample Output

3
1

Hint

For the first sample test case, DreamGrid can choose  and changes  to .

For the second sample test case, no matter which  DreamGrid chooses, he can only get at most 1 match.

Original title address: http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5753

The meaning of the question: Give you two arrays A, B, and ask you to add a number or subtract a number to all elements of the A array at the same time, or the maximum number that is the same as the B array after it remains unchanged;

Idea: Because the number added to array A is the same, the number of differences is still the same after the change of array A, so directly calculate the maximum number of differences between array A and array B, because there may be negative numbers, so use map Easy and simple, map is really a good thing

Code:

#include<bits/stdc++.h>
using namespace std;

int a[5000000];
int b[5000000];
int main()
{
    std::ios::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        map<int,int>mp;
        int n;
        cin>>n;
        for(int i=0;i<n;i++){
                cin>>a[i];
        }
        for(int i=0;i<n;i++){
                cin>>b[i];
        }
        for(int i=0;i<n;i++){
                mp [a [i] -b [i]] ++ ;
        }
        int maxn=0;
        map<int,int>::iterator it;
        for(it=mp.begin();it!=mp.end();it++){
                if(it->second>maxn){
                        maxn=it->second;
                }
        }
        cout<<maxn<<endl;
    }
    return 0;
}

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325092056&siteId=291194637