2019ccpc女生赛function

#include
#define ll long long
using namespace std;
ll n,m,c;
struct node{
    ll a ,b, x;
    ll sum;
    bool operator< (const node& p) const {
        if(sum != p.sum) return sum > p.sum;
        else return a > p.a;
    }
}f[100050];

int main(){
    priority_queue<node> que;
    scanf("%lld%lld",&n,&m);
    ll ans = 0 ; 
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld%lld",&f[i].a,&f[i].b,&c);
        ans += f[i].a+f[i].b+c;
        f[i].x  = 1;
        f[i].sum = 2*f[i].a*f[i].x+f[i].b+f[i].a;
        
        que.push(f[i]);
    } 
    m-=n;
    while(m--)
    {
        node t = que.top();
        que.pop() ;
        ans += t.sum;
          t.x ++;
        t.sum = 2*t.a*t.x+t.b+t.a;
        que.push(t);
    }
    cout << ans<<endl;
     return 0;
}

你可能感兴趣的:(2019ccpc女生赛function)