首页 > 其他分享 >Codeforces Round 946 (Div. 3)

Codeforces Round 946 (Div. 3)

时间:2024-08-13 20:49:14浏览次数:7  
标签:946 Codeforces long int solve Div now

### G.
一眼看上去很想个背包,然后发现好像不大能做。
考虑反悔贪心。
对于当前的 $c_i$,如果到现在攒的钱足够买这个,那就直接买了它。如果钱不够,就从之前的买过的里面把一个最大的给退掉,然后买这个,优先队列维护即可。
```c++ #include<bits/stdc++.h> #define int long long using namespace std;
const int N = 1e6 + 7; int c[N]; void solve() {     int n, x;     cin >> n >> x;     for(int i = 1; i <= n; i ++) {         cin >> c[i];     }     int now = 0;     priority_queue<int> q;     for(int i = 1; i <= n; i ++) {         if(c[i] <= now) {             now -= c[i];             q.push(c[i]);         }         else {             if(!q.empty() && q.top() > c[i]) {                 int u = q.top();                 q.pop();                 now = now + u - c[i];                 q.push(c[i]);                             }         }         now += x;     }     cout << q.size() << endl; } signed main() {     int T;     cin >> T;     while(T --) solve(); } ```

标签:946,Codeforces,long,int,solve,Div,now
From: https://www.cnblogs.com/wyyqwq/p/18357665

相关文章

  • Codeforces Round 964 (Div. 4)
    ###A.```c++#include<bits/stdc++.h>usingnamespacestd;constintN=1e6+7;voidsolve(){  intx;  cin>>x;  cout<<x/10+x%10<<endl;}intmain(){  intT;  cin>>T;  while(T--)solve();......
  • 【做题记录】Codeforces Round 915 (Div. 2)/CF1905A-F
    @目录A.ConstructiveProblems(800)B.Begginer'sZelda(1100)C.LargestSubsequence(1400)D.CyclicMEX(2000)E.One-X(2400)F.FieldShouldNotBeEmpty(2600)提交记录A.ConstructiveProblems(800)注意到,对于\(n\timesn\)的矩阵,只需要把对角线全染黑即可。推广到\(......
  • Codeforces Round 903 (Div. 3) F. Minimum Maximum Distance
    https://codeforces.com/contest/1881/problem/F不难发现一件事情,我们这里最后的答案所在的点是1和3号点。我们有没有发现一个性质:就是这两个点都是红点间的路径上的,而且最后的答案就是最长的红点间的距离的长度除以二上取整。那么,我们怎么找到最长的红点间的距离呢?很显......
  • Codeforces Round 964 (Div. 4)
    CodeforcesRound964(Div.4)标题CodeForces1999A.A+BAgain?时限1second空限256megabytes题目描述给定一个两位数的正整数\(n\),求其数字之和。输入第一行包含一个整数\(t\)(\(1\leqt\leq90\))——测试用例的数量。每个测试用例的唯一一行包含一个两位数的正......
  • AGC182 C - Sum of Number of Divisors of Product
    题目大意:求长度为1,2,...N,的好序列因数个数。好序列满足每个元素\(1\leqx\leqM\)\(N\leq1e18,M\leq16\)很容易想到维护所有好序列质因数的指数+1的乘积。\(\prodb_i,1\leqi\leq6\).考虑每个数对这个乘积的影响。假设我们只有2,3,5这三个质数,序列末端添加15,......
  • 965div2补题
    A.FindKDistinctPointswithFixedCenter思路简单构造,我居然在这个题上因为没看懂英文还有机翻英太过逆天导致我WA了好几发......ACcode:#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;voidsolve(){intx,y,k;cin>>x>>y>>k;in......
  • EPIC Institute of Technology Round August 2024 (Div. 1 + Div. 2) 补题记录(A~D1,E)
    A容易发现答案为\(\min(n,k)\min(m,k)\)。#include<bits/stdc++.h>#defineintlonglong#definepbpush_backusingnamespacestd;constintN=1000100;inta[N];signedmain(){intT;cin>>T;while(T--){intn,m,k;cin>>n&g......
  • Codeforces Round 963 (Div. 2)
    Preface有懒狗上周日的比赛拖到这周日才写博客,我不说是谁这场比赛的时候因为C数组没开两倍卡了1h最后写对拍才看出来,直接心态爆炸导致D没写完掉大分A.QuestionMarks签到#include<cstdio>#include<iostream>#include<utility>#include<vector>#include<cstring>......
  • CF1998 div2 & abc366
    1CF1.1B被诈骗了。我们的构造要向“每个区间只有1个数不一样考虑”。1.2C比较难。但是出的好。注意到如果我们不删除中位数这个位置的数,那么那个数是一定的。所以我们可以把\(k\)加到最大的可以加的数上,统计答案就在这个数,然后二分算中位数即可。其它策略?我们可不......
  • Codeforces Round 965 (Div. 2) 题解
    个人难度顺序:A<D<B<C<E。A.FindKDistinctPointswithFixedCenter如果\(k\)是偶数,构造\((x_c+i,yc+i)\),其中\(-\frac{k}{2}\lei\le\frac{k}{2}\)。对于\(k\)是奇数,先加一个点\((xc,yc)\),然后就变成偶数的情况了。B.MinimizeEqualSumSubarr......