首页 > 其他分享 >CodeForces 1132B Discounts

CodeForces 1132B Discounts

时间:2024-08-01 16:09:44浏览次数:14  
标签:1132B 巧克力 int CodeForces Discounts include

题目链接:CodeForces 1132B【Discounts】



思路

       因为使用coupons购买q[i]块巧克力,不需要付最便宜的那块巧克力的钱,所以为了使得优惠最大化,所以可以在使用优惠券的时候购买最贵的p[i]块巧克力,所以计算所有巧克力价格高之和和排序后很快能得到答案。


代码

#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define ll long long
const int N = 3e5 + 10;

ll a[N], q[N], sum, n, m;
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    cin >> q[i];
  }
  sort(a + 1, a + 1 + n);

  for (int i = 1; i <= m; i++) {
    cout << sum - a[n - q[i] + 1] << endl;
  }
}

int main() {
  int t = 1;
  while (t--) {
    solve();
  }

  return 0;
}

标签:1132B,巧克力,int,CodeForces,Discounts,include
From: https://www.cnblogs.com/againss/p/18336850

相关文章

  • CodeForces 1873A Short Sort
    题目链接:CodeForces1873A【ShortSort】思路    签到题,因为能交换两个元素的位置,所以只需要判断是否有一个元素在他原来该在的位置上就行。代码#include<iostream>#include<cstring>usingnamespacestd;#definelllonglongconstintN=1e5+10;void......
  • CodeForces 908C New Year and Curling
    题目链接:CodeForces908C【NewYearandCurling】思路    模拟,考虑到两个圆盘可能出现y值相同且相接的情况,所以在判断当前圆盘的y值时循环的范围从在前圆盘的x值左右浮动2r,依次遍历这个范围内的数组y(存储的是当前已经移动了圆盘中的横坐标为i的圆盘的最大的y值),然后可......
  • Codeforces 11D A Simple Task 题解 [ 蓝 ] [ 状压 dp ]
    思路不难想,细节比较多。思路观察到\(n\le19\),首先想到状压dp。于是自然地定义\(dp[j][i]\)为:抵达点的状态为\(i\),且此时在点\(j\)时,简单路径的条数。注意这里是简单路径的条数,而不是环的个数,因为环的个数要在dp过程中统计。这里的dp作用就在于求简单路径条数。......
  • Codeforces Round 943 (Div. 3)A~E
    A.Maximize?题目大意:给你一个数x,你需要找到一个数y(1<=y<x),使得gcd(x,y)+y值最大,然后输出这个y思路:看范围暴力即可voidsolve(){inta,b=0,maxx=0,bj=0;cin>>a;for(inti=1;i<a;i++){b=__gcd(a,i);b+=i;if(maxx<b)......
  • Educational Codeforces Round 168 (Rated for Div. 2) (4/6)
    比赛链接:https://codeforces.com/contest/1997solve:ABCD开头:终于能上青名了,本来以为还得打个两三场,看来这暑假必须上蓝名了,不过这一场说实话感觉运气成分大一点,先稳住青名,最近感觉有点懒惰了,欠了好几场补题,牛客多校还有好多场qwq,得努力了A.StrongPassword思路:......
  • Educational Codeforces Round 168 (Rated for Div. 2) 补题记录(A~E)
    A直接暴力枚举字符添加在哪里,以及添加的字符是什么即可。#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=500100;signedmain(){intT;cin>>T;while(T--){strings;cin>>s;stringans;i......
  • Codeforces Round 933 (Div. 3) D 题
    D.RudolfandtheBallGame原题链接:https://codeforces.com/contest/1941/problem/D RudolfandBernarddecidedtoplayagamewiththeirfriends. n peoplestandinacircleandstartthrowingaballtoeachother.Theyarenumberedfrom 1 to nn i......
  • Codeforces Round 929 (Div. 3)---->E. Turtle vs. Rabbit Race: Optimal Trainings
    https://codeforces.com/contest/1933/problem/E#include<bits/stdc++.h>#definexfirst#defineysecondusingnamespacestd;typedeflonglongll;typedef__int128i128;typedefpair<int,int>pii;constintN=2e5+10,M=110;intn,q;inta[N];ll......
  • Codeforces Round 958 (Div. 2)A(AC)BC(补题)
    这里写目录标题A思维题【AC】B贪心(+双指针)【补题】冗余代码(我的):大佬:双指针代码借鉴后代码C异或问题【补题】A思维题【AC】思路:每次分成k-1个1,1个其他#include<iostream>#include<cstring>#include<algorithm>usingnamespacestd;//constintN=2e5+10;v......
  • 题解:Codeforces Round 962 (Div. 3) D
    D.Funtimelimitpertest:2secondsmemorylimitpertest:256megabytesinput:standardinputoutput:standardoutputCountingisFun!—satyam343Giventwointegers\(n\)and\(x\),findthenumberoftriplets(\(a,b,c\))ofpositiveintegerss......