• C. Choosing flowers


    C - Choosing flowers

    实力不够,经验不足,心态不稳,哎
    假设最优策略里面选择了几种买了不止一支,其余的可能只卖了一支,就直接按照a的从大到小买,对于b的贡献,按照b排序,那么b序列的贡献

    [b[x1]>b[x2]>b[x3] ]

    既然这样,我还傻着逼脸买后面的,我脑子哎,都直接买第一个就行了,所以就直接最多最多存在一支花买了好多个,其余买一支的就直接按照a的大小买。枚举一下b就行了,

    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <unordered_map>
    #include <vector>
    #include <map>
    #include <list>
    #include <queue>
    #include <cstring>
    #include <cstdlib>
    #include <ctime>
    #include <cmath>
    #include <stack>
    #include <set>
    #pragma GCC optimize(3 , "Ofast" , "inline")
    using namespace std ;
    #define ios ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0)
    #define x first
    #define y second
    typedef long long ll ;
    const double esp = 1e-6 , pi = acos(-1) ;
    typedef pair<ll , ll> PII ;
    const int N = 1e6 + 10 , INF = 0x3f3f3f3f , mod = 1e9 + 7;
    ll in()
    {
      ll x = 0 , f = 1 ;
      char ch = getchar() ;
      while(!isdigit(ch)) {if(ch == '-') f = -1 ; ch = getchar() ;}
      while(isdigit(ch)) x = x * 10 + ch - 48 , ch = getchar() ;
      return x * f ;
    }
    PII a[N] ;
    ll c[N] , d[N] ;
    void work(){
      int n = in() , m = in() ;
      for(int i = 1; i <= m ;i ++ )  a[i].x = in() , a[i].y = in() ;
      sort(a + 1 , a + m + 1) ;
      for(int i = 1; i <= m ;i ++ ) d[i] = a[i].x , c[i] = c[i - 1] + a[i].x ;
      ll ans = 0 ;
      if(n <= m) ans = c[m] - c[m - n] ;
      for(int i = 1; i <= m ;i ++ ) {
        int pos = lower_bound(d + 1 ,d + m + 1 , a[i].y) - d ;
        int x = m - pos + 1 ;
        if(n >= x) 
          ans = max(ans , c[m] - c[pos - 1] + 1ll * (n - x) * a[i].y + (pos > i ? a[i].x - a[i].y : 0)) ;
      }
      printf("%lld
    " , ans) ;
      return ;
    }
    int main()
    {
      int t = in() ;
      while(t --) work() ;
      return 0 ;
    }
    /*
    */
    
    
    
  • 相关阅读:
    Spoj-ANTP Mr. Ant & His Problem
    Spoj-BIPCSMR16 Team Building
    cf575A Fibonotci
    cf660E Different Subsets For All Tuples
    cf468C Hack it!
    cf468B Two Sets
    cf701E Connecting Universities
    Spoj-BLMIRINA Archery Training
    Spoj-BITDIFF Bit Difference
    Spoj-VISIBLEBOX Decreasing Number of Visible Box
  • 原文地址:https://www.cnblogs.com/spnooyseed/p/13342147.html
Copyright © 2020-2023  润新知