Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1)题解

Problem A

就特判一下2和1,其他看一下奇偶就好了。

Problem B

看是否有一样的字母

Problem C

贪心贪不出来,要死了,哇哇大哭。结果还是个二分题,二分答案,然后贪心的判定就好了。

Code

#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+10;
typedef long long ll;
void check_max (int &a,int b) {a=max (a,b);}
ll lim;
int a[maxn],st[maxn];
int n,temp[maxn];
int p[maxn];

bool check (int mid) {
  ll ans=0;
  memset (temp,0,sizeof (temp));
  for (int i=1;i<=mid;i++) temp[i]=st[i];
  sort (temp+1,temp+1+mid); reverse (temp+1,temp+mid+1);
  for (int i=1;i<=n;i++) {
    ans+=temp[i]*a[i];
    if (ans>=lim) return true;
  }
  return false;
}

int main () {
  int t;
  scanf ("%d",&t);
  while (t--) {
    scanf ("%d",&n);
    memset (a,0,sizeof (a));
    for (int i=1;i<=n;i++) scanf ("%d",&a[i]),a[i]/=100;
    sort (a+1,a+n+1);
    reverse (a+1,a+n+1);
    int pos,gap;
    memset (st,0,sizeof (st));
    scanf ("%d%d",&gap,&pos);
    for (int i=pos;i<=n;i+=pos) st[i]+=gap;
    scanf ("%d%d",&gap,&pos);
    for (int i=pos;i<=n;i+=pos) st[i]+=gap;
    scanf ("%lld",&lim);
    ll now=0;
    memset (p,0,sizeof (p));
    for (int i=1;i<=n;i++) p[i]=st[i];
    sort (p+1,p+n+1); reverse (p+1,p+n+1);
    for (int i=1;i<=n;i++) now+=p[i]*a[i];
    if (now<lim) printf ("-1\n");
    else {
      int l=0,r=n;
      while (l<r) {
        int mid=(l+r)>>1;
        if(check (mid)) r=mid;
        else l=mid+1;
      }
      printf ("%d\n",l);
    }
  }
  return 0;
}
posted @ 2020-11-04 15:43  Luglucky  阅读(54)  评论(0编辑  收藏  举报