Codeforces Round 916 (Div. 3) C题 Quests

问题标签

贪心(greedy)

数学(math)

*1100

原题链接:

Problem - C - Codeforces 

题目描述

Monocarp is playing a computer game. In order to level up his character, he can complete quests. There are nn quests in the game, numbered from 1 to n .

Monocarp can complete quests according to the following rules:

  • the 1 -st quest is always available for completion;
  • the i -th quest is available for completion if all quests j<i have been completed at least once.

Note that Monocarp can complete the same quest multiple times.

For each completion, the character gets some amount of experience points:

  • for the first completion of the i -th quest, he gets aiai​ experience points;
  • for each subsequent completion of the i -th quest, he gets bibi​ experience points.

Monocarp is a very busy person, so he has free time to complete no more than k quests. Your task is to calculate the maximum possible total experience Monocarp can get if he can complete no more than k quests.

输入格式

The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases.

The first line of each test case contains two integers nn and kk ( 1≤n≤2⋅105 ; 1≤k≤2⋅105 ) — the number of quests and the maximum number of quests Monocarp can complete, respectively.

The second line contains nn integers a1,a2,…,an​ ( 1≤ai≤103 ).

The third line contains nn integers b1,b2,…,bn( 1≤bi≤103 ).

Additional constraint on the input: the sum of nn over all test cases does not exceed 2⋅105.

输出格式

For each test case, print a single integer — the maximum possible total experience Monocarp can get if he can complete no more than k quests.

题意翻译

有 n 个任务,在完成 i 任务时,i 之前的所有任务都必须完成。同时,可以多次完成某个任务。总共可以做 k 次任务,第一次完成 i 任务的贡献为 ai​ ,后面完成 i 任务的贡献为 bi​ ,求最大贡献。

输入输出样例

输入 #1复制

4
4 7
4 3 1 2
1 1 1 1
3 2
1 2 5
3 1 8
5 5
3 2 4 1 4
2 3 1 4 7
6 4
1 4 5 4 5 10
1 5 1 2 5 1

输出 #1复制

13
4
15
15

说明/提示

In the first test case, one of the possible quest completion sequences is as follows: 1,1,2,3,2,4,4 ; its total experience is equal to 4‾+1+3‾+1‾+1+2‾+1=13(the underlined numbers correspond to the instances when we complete a quest for the first time).

In the second test case, one of the possible quest completion sequences is as follows: 1,1 ; its total experience is equal to 1‾+3=4 .

In the third test case, one of the possible quest completion sequences is as follows: 1,2,2,2,3 ; its total experience is equal to 3‾+2‾+3+3+4‾=15 .

思路: 

这是一道贪心的题目,开始的时候我还使用动态规划去做这道题,发现不太适合,这时我有想起来这道题前两天刚做的 http://t.csdnimg.cn/c2m8R 这道题,与这道题很类似,他都是关于是否要在某个位置进行停留,要停留多久,进行一定的轮数,然后呢,要求一定轮数下来的可以得到的最大分数呢,或则是最大经验值,反正就是求个最大值,我们就想起上篇文章的暴力枚举了,因为他一共就n个位置,如果n个位置都走完了以后,还有剩余的轮数的话,我们肯定剩余的轮数都选择b[i] 当中最大的那个值去走,即走完n个位置的得分加上剩余轮数*b数组的最大值,那么对于走了k轮,其实就是枚举一下每一个i,我们对于k轮,每次都让其往前走,然后计算一下走了这么多步,如果剩余的不再往前走的最大值是多少,这样就可以求解出最大值,我说的可能比较难懂,其实你们看代码就理解了

 

#include<bits/stdc++.h>

using namespace std;

void solve()
{
    int n,k;
    cin>>n>>k;

    vector<int> a(n);
    vector<int> b(n);

    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    for(int i=0;i<n;i++)
    {
        cin>>b[i];
    }

    long long sum=0;
    long long ans=0;

    int curmax=0;

    for(int i=0;i<min(n,k);i++)
    {
        sum+=a[i];
        curmax=max(curmax,b[i]);
        ans=max(ans,1LL*(k-i-1)*curmax+sum);
    }

    cout<<ans<<endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

  • 31
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Codeforces Round 894 (Div. 3) 是一个Codeforces举办的比赛,是第894轮的Div. 3级别比赛。它包含了一系列目,其中包括目E. Kolya and Movie Theatre。 根据目描述,E. Kolya and Movie Theatre问要求我们给定两个字符串,通过三种操作来让字符串a等于字符串b。这三种操作分别为:交换a中相同位置的字符、交换a中对称位置的字符、交换b中对称位置的字符。我们需要先进行一次预处理,替换a中的字符,然后进行上述三种操作,最终得到a等于b的结果。我们需要计算预处理操作的次数。 根据引用的讨论,当且仅当b[i]==b[n-i-1]时,如果a[i]!=a[n-i-1],需要进行一次操作;否则不需要操作。所以我们可以遍历字符串b的前半部分,判断对应位置的字符是否与后半部分对称,并统计需要进行操作的次数。 以上就是Codeforces Round 894 (Div. 3)的简要说明和目E. Kolya and Movie Theatre的要求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [Codeforces Round #498 (Div. 3) (A+B+C+D+E+F)](https://blog.csdn.net/qq_46030630/article/details/108804114)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Codeforces Round 894 (Div. 3)A~E解](https://blog.csdn.net/gyeolhada/article/details/132491891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值