zoukankan      html  css  js  c++  java
  • 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 ;
    }
    /*
    */
    
    
    
  • 相关阅读:
    Oracle:SQL语句--对表的操作——删除表
    Oracle:SQL语句--对表的操作——修改表名
    Oracle:SQL语句--对表的操作——修改表名
    Oracle:SQL语句--对表的操作—— 删除字段(即删除列)
    网络配置4:vlan间通信配置
    网络配置3:动态路由配置
    网络配置2:静态路由配置
    网络配置0:网络设备基础知识
    网络配置1:VLAN配置
    T-SQL之数据操作(一):增删改
  • 原文地址:https://www.cnblogs.com/spnooyseed/p/13342147.html
Copyright © 2011-2022 走看看