74分跪求debug(#7,#8wa),set+map求解
查看原帖
74分跪求debug(#7,#8wa),set+map求解
1159333
A_Little_BadBoy楼主2023/12/21 23:41
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n,m,p,a;//题目要求
int total=0;//记录总价格
map<int,int>t1;//存放单价和数量
set<int>t2;//存放单价

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>p>>a;
        if(!t1.count(a))t1[p]=a;
        else t1[p]+=a;
        t2.insert(p);
    }
    for(auto i:t2)//从最小值开始遍历单价
    {
        int temp=min(n,t1[i]);//取min(该单价的总牛奶数,目前还需的总牛奶数)
        total+=i*temp;
        n-=temp;
        if(!n)break;//n==0结束循环
    }
    cout<<total;
    return 0;
}
2023/12/21 23:41
加载中...