CF1132B Discounts

    • 45通过
    • 75提交
  • 题目来源 CodeForces 1132B
  • 评测方式 RemoteJudge
  • 标签
  • 难度 普及-
  • 时空限制 2500ms / 256MB

题解

  • 提示:收藏到任务计划后,可在首页查看。
  • 体验新版界面

    最新讨论 显示

    推荐的相关题目 显示

    题意翻译

    输入n个整数($a_1...a_n$)和 $m$ 个整数( $q_1...q_m$ )。求在去掉第 $q_i$ 大的数字后,$n-1$ 个整数的和。

    输入输出格式

    输入格式:

    共有4行输入。第1行输入一个整数 $n$ ( $2≤n≤3·10^5$ ),第2行输入$n$个整数 $a_1...a_n$( $1≤ai≤10^9 $ ),第3行输入一个整数$m$( $1≤m≤n$ ),第 $4$ 行输入 $m$ 个整数 $q_1...q_m$( $2≤q_i≤n$ )。

    输出格式:

    输出$m$个数字,第i行输出表示去掉第$q_i$大的数字后剩下整数的和。

    说明

    样例中,输入3,去掉数组中第3大的整数7,剩下的数字和为27;输入4,去掉数组中第4大的数字4,和为30。

    题目描述

    You came to a local shop and want to buy some chocolate bars. There are $ n $ bars in the shop, $ i $ -th of them costs $ a_i $ coins (and you want to buy all of them).

    You have $ m $ different coupons that allow you to buy chocolate bars. $ i $ -th coupon allows you to buy $ q_i $ chocolate bars while you have to pay only for the $ q_i - 1 $ most expensive ones (so, the cheapest bar of those $ q_i $ bars is for free).

    You can use only one coupon; if you use coupon $ i $ , you have to choose $ q_i $ bars and buy them using the coupon, and buy all the remaining $ n - q_i $ bars without any discounts.

    To decide which coupon to choose, you want to know what will be the minimum total amount of money you have to pay if you use one of the coupons optimally.

    输入输出格式

    输入格式:

    The first line contains one integer $ n $ ( $ 2 \le n \le 3 \cdot 10^5 $ ) — the number of chocolate bars in the shop.

    The second line contains $ n $ integers $ a_1 $ , $ a_2 $ , ..., $ a_n $ ( $ 1 \le a_i \le 10^9 $ ), where $ a_i $ is the cost of $ i $ -th chocolate bar.

    The third line contains one integer $ m $ ( $ 1 \le m \le n - 1 $ ) — the number of coupons you have.

    The fourth line contains $ m $ integers $ q_1 $ , $ q_2 $ , ..., $ q_m $ ( $ 2 \le q_i \le n $ ), where $ q_i $ is the number of chocolate bars you have to buy using $ i $ -th coupon so that the least expensive of them will be for free. All values of $ q_i $ are pairwise distinct.

    输出格式:

    Print $ m $ integers, $ i $ -th of them should be the minimum amount of money you have to pay if you buy $ q_i $ bars with $ i $ -th coupon, and all the remaining bars one by one for their full price.

    输入输出样例

    输入样例#1: 复制
    7
    7 1 3 1 4 10 8
    2
    3 4
    
    输出样例#1: 复制
    27
    30
    

    说明

    Consider the first example.

    If we use the first coupon, we may choose chocolate bars having indices $ 1 $ , $ 6 $ and $ 7 $ , and we pay $ 18 $ coins for them and $ 9 $ coins for all other bars.

    If we use the second coupon, we may choose chocolate bars having indices $ 1 $ , $ 5 $ , $ 6 $ and $ 7 $ , and we pay $ 25 $ coins for them and $ 5 $ coins for all other bars.

    提示
    标程仅供做题后或实在无思路时参考。
    请自觉、自律地使用该功能并请对自己的学习负责。
    如果发现恶意抄袭标程,将按照I类违反进行处理。