7个AC,最后三组数据WA,求佬帮看看问题
查看原帖
7个AC,最后三组数据WA,求佬帮看看问题
1301968
BertZzz楼主2024/4/11 22:40
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}

int main(){
    vector<int> offer;
    int n,m;

    cin >> n >> m;
    for (int i = 0;i < m;i++){
        int price = 0;
        cin >> price;
        offer.push_back(price);
    }

    sort(offer.begin(),offer.end());
    vector<int> profit;

    for(int i = 0;i < min(m,n);i++){
        int gain = 0;
        gain = (min(m,n) - i)*offer[i];
        profit.push_back(gain);
    }

    int j = 0;
    while (profit[j]<profit[j+1]){
        j++;
    }

    cout << offer[j] << " " << profit[j] << endl;
    return 0;
}

2024/4/11 22:40
加载中...