错哪了T-T

回复帖子

@TonyStark 2018-09-14 14:28 回复
#include<iostream>
#include<cstdio>
#include<algorithm> 
using namespace std;
struct pack{
    int weight;
    int value;
    double price;
};
pack w[10000010];
bool cmp(pack x,pack y)
{
    return x.price>y.price;
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>w[i].weight>>w[i].value;
        w[i].price=double(w[i].value)/double(w[i].weight);
    }
    sort(w+1,w+n+1,cmp);
    int temp=0;
    int ans=0;
    int cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(temp<=m&&temp+w[i].weight>m)
        {
            cout<<ans<<endl;
            return 0;
        }
        temp+=w[i].weight;
        ans+=w[i].value;
        //cout<<w[i].weight<<" "<<w[i].value<<" "<<w[i].price<<" "<<i<<endl; 
    }
    return 0;
} 
反馈
如果你认为某个帖子有问题,欢迎向洛谷反馈,以帮助更多的同学。



请具体说明理由,以增加反馈的可信度。