King of Karaoke ZOJ - 4025

https://vjudge.net/problem/ZOJ-4025/origin

https://vjudge.net/contest/399385#problem/B

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 $D_1, D_2, \dots, D_n$, and the standard version of the song can be considered as another integer sequence $S_1, S_2, \dots, S_n$. The score is the number of integers $i$ satisfying $1 \le i \le n$ and $S_i = D_i$.

As a good tuner, DreamGrid can choose an integer $K$ (can be positive, 0, or negative) as his tune and add $K$ to every element in $D$. 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 $T$ (about 100), indicating the number of test cases. For each test case:

The first line contains one integer $n$ ($1 \le n \le 10^5$), indicating the length of the sequences $D$ and $S$.

The second line contains $n$ integers $D_1, D_2, \dots, D_n$ ($-10^5 \le D_i \le 10^5$), indicating the song performed by DreamGrid.

The third line contains $n$ integers $S_1, S_2, \dots, S_n$ ($-10^5 \le S_i \le 10^5$), indicating the standard version of the song.

It's guaranteed that at most 5 test cases have $n > 100$.

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 $K = 1$ and changes $D$ to $\{2,3,4,5\}$.

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

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

int S[100005] = {0};
int D[100005] = {0};
int sub[400005] = {0};
int main()
{
    int T = 0;
    cin >> T;
    while(T--)
    {
        int n = 0;
        cin >> n;
        for(int i = 0;i<=400000;i++)
        {
            sub[i] = 0;
        }
        
        for(int i = 0;i<n;i++)
        {
            cin >> D[i];
        }
        for(int i = 0;i<n;i++)
        {
            cin >> S[i];
        }
        for(int i = 0;i<n;i++)
        {
            int SUB = D[i] - S[i];
            sub[SUB + 200000] += 1;
        }
        int maxp = 0;
        int max = sub[0];
        for(int i = 0;i <= 400000;i++)
        {
            if(sub[i] > max)
            {
                maxp = i;
                max = sub[i];
            }
        }
        cout << max << endl;
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YukiRinLL

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值