

Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
#include <bits/stdc++.h>
using namespace std;
struct infor{
int price;
int quantity;
};
bool compare(infor a, infor b){
return a.price < b.price;
}
int main(){
int s, n;
cin >> s >> n;
vector <infor> candies(n);
for(int i = 0; i < n; i++){
cin >> candies[i].price >> candies[i].quantity;
}
sort(candies.begin(), candies.end(), compare);
int kq = 0;
for(int i = 0; i < n; i++){
int can = min(s / candies[i].price, candies[i].quantity);
kq += can;
s -= can * candies[i].price;
if(s == 0){
break
}
}
cout << kq << endl;
}
#vocongthanh
Hãy giúp mọi người biết câu trả lời này thế nào?

Bảng tin