WEEK6&&CF(Good Bye 2022: 2023 is NEAR)

A. Koxia and Whiteboards

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

Kiyora has nn whiteboards numbered from 11 to nn. Initially, the ii-th whiteboard has the integer aiai written on it.

Koxia performs mm operations. The jj-th operation is to choose one of the whiteboards and change the integer written on it to bjbj.

Find the maximum possible sum of integers written on the whiteboards after performing all mm operations.

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn and mm (1≤n,m≤1001≤n,m≤100).

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

The third line of each test case contains mm integers b1,b2,…,bmb1,b2,…,bm (1≤bi≤1091≤bi≤109).

Output

For each test case, output a single integer — the maximum possible sum of integers written on whiteboards after performing all mm operations.

Example

input

Copy

43 21 2 34 52 31 23 4 51 110015 31 1 1 1 11000000000 1000000000 1000000000

output

Copy

12

9

1

3000000002

Note

In the first test case, Koxia can perform the operations as follows:

  1. Choose the 11-st whiteboard and rewrite the integer written on it to b1=4b1=4.

  1. Choose the 22-nd whiteboard and rewrite to b2=5b2=5.

After performing all operations, the numbers on the three whiteboards are 44, 55 and 33 respectively, and their sum is 1212. It can be proven that this is the maximum possible sum achievable.

In the second test case, Koxia can perform the operations as follows:

  1. Choose the 22-nd whiteboard and rewrite to b1=3b1=3.

  1. Choose the 11-st whiteboard and rewrite to b2=4b2=4.

  1. Choose the 22-nd whiteboard and rewrite to b3=5b3=5.

The sum is 4+5=94+5=9. It can be proven that this is the maximum possible sum achievable.

根据题意,每次用取出用可替换的值换掉原数组中最小的值,利用小根堆实现。一开始理解错了题意....

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


ll n,m,t,k,ans;
priority_queue<ll,vector<ll>,greater<ll> > q;

int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        ans=0;
        for(int i=1;i<=n;i++)
        {
            cin>>k;
            q.push(k);
        }
        for(int i=1;i<=m;i++)
        {
            cin>>k;
            q.pop();
            q.push(k);
        }
        while(!q.empty())
        {
            ans+=q.top();
            q.pop();
        }
        cout<<ans<<endl;
    }
    return 0;
}

B. Koxia and Permutation

time limit per test1 second

memory limit per test256 megabytes

inputstandard input

outputstandard output

Reve has two integers nn and kk.

Let pp be a permutation†† of length nn. Let cc be an array of length n−k+1n−k+1 such that

ci=max(pi,…,pi+k−1)+min(pi,…,pi+k−1).ci=max(pi,…,pi+k−1)+min(pi,…,pi+k−1).

Let the cost of the permutation pp be the maximum element of cc.

Koxia wants you to construct a permutation with the minimum possible cost.

†† A permutation of length nn is an array consisting of nn distinct integers from 11 to nn in arbitrary order. For example, [2,3,1,5,4][2,3,1,5,4] is a permutation, but [1,2,2][1,2,2] is not a permutation (22 appears twice in the array), and [1,3,4][1,3,4] is also not a permutation (n=3n=3 but there is 44 in the array).

Input

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤20001≤t≤2000) — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105).

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105.

Output

For each test case, output nn integers p1,p2,…,pnp1,p2,…,pn, which is a permutation with minimal cost. If there is more than one permutation with minimal cost, you may output any of them.

Example

input

Copy

35 35 16 6

output

Copy

5 1 2 3 4

1 2 3 4 5

3 2 4 1 6 5

Note

In the first test case,

  • c1=max(p1,p2,p3)+min(p1,p2,p3)=5+1=6c1=max(p1,p2,p3)+min(p1,p2,p3)=5+1=6.

  • c2=max(p2,p3,p4)+min(p2,p3,p4)=3+1=4c2=max(p2,p3,p4)+min(p2,p3,p4)=3+1=4.

  • c3=max(p3,p4,p5)+min(p3,p4,p5)=4+2=6c3=max(p3,p4,p5)+min(p3,p4,p5)=4+2=6.

Therefore, the cost is max(6,4,6)=6max(6,4,6)=6. It can be proven that this is the minimal cost.

经过观察,找到规律,如果是奇数最后在处理一下。

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

int n,k,t;

int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n>>k;
        for(int i=1;i*2-1<n;i++)
        {
            cout<<n-i+1<<" "<<i<<" ";
        }
        if(n%2==1)
            cout<<n/2+1<<endl;
    }
    return 0;
}

复制Markdown 展开

题目描述

你有 qq 个相同颜色的颜料,和一个 nn 行 mm 列的棋盘。

你计划在棋盘上涂 qq 个格子,对于第 ii 个要涂的格子,用 (x_i, y_i,t_i)(xi,yi,ti) 表示 在 t_iti 时刻涂一个位于 (x_i, y_i)(xi,yi) 的格子。

问,最早什么时候棋盘上会形成一个边长至少为 kk 的正方形。

输入格式

第一行有 44 个整数, n, m, k,q(1 \leq n,m\leq 500, 1 \leq k \leq \min(n,m), 0 \leq q \leq n *m)n,m,k,q(1≤n,m≤500,1≤k≤min(n,m),0≤qnm)。

接下来的 qq 行,每行三个整数 x_i, y_i, t_i(1 \leq x_i \leq n, 1 \leq y_i \leq m, 0 \leq t \leq 10^9 )xi,yi,ti(1≤xin,1≤yim,0≤t≤109)。

输出格式

输出一个整数,表示棋盘上形成一个边长至少为 kk 的正方形的最早时刻,如果不存在输出 -1−1。

输入输出样例

输入 #1复制

2 3 2 5

2 1 8

2 2 8

1 2 1

1 3 4

2 3 2

输出 #1复制

8

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值