CodeM 资格赛 B 可乐 思维

 

分析: 我们假设购买一种可乐p瓶,我们可以得到期望:p*(m/n*a[i]+(n-m)/n*b[i]),由这个式子我们可以看出唯一的变量是i,所以可以遍历i找出式子的最大值

 

#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(a) cout << #a << " " << a << endl
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;
typedef long long ll;
ll a[maxn], b[maxn];
int main() {
    ll n, m, k;
    while( cin >> n >> m >> k ) {
        ll sum = -1e9, j = 0, flag;
        for( ll i = 0; i < k; i ++ ) {
            cin >> a[i] >> b[i];
            if( m*a[i]+(n-m)*b[i] >= sum ) {
                flag = i;
                sum = m*a[i]+(n-m)*b[i];
            }
        }
        for( ll i = 0; i < k; i ++ ) {
            if( m*a[i]+(n-m)*b[i] == sum && i == flag ) { //取字典序最小
                if( i == 0 ) {
                    cout << n;
                } else {
                    cout << " " << n;
                }
            } else {
                if( i == 0 ) {
                    cout << 0;
                } else {
                    cout << " " << 0;
                }
            }
        }
        cout << endl;
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/l609929321/p/9314625.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值