#include #include #include #include using namespace std;vector > data;int main(void){ int n , m; while (1) { cin >> n >> m; if (n == 0 && m == 0) { break; } int maxd = 0; data.clear(); pair temp; for (int i = 0 ; i < n ; i++) { cin >> temp.second >> temp.first; maxd += temp.first * temp.second; data.push_back(temp); } sort(data.begin() , data.end()); vector >::reverse_iterator begin = data.rbegin(); vector >::reverse_iterator end = data.rend(); for (; begin != end ; begin++) { int length = min(begin->second , m); maxd -= (length * begin->first); m -= length; if (m <= 0) { break; } } maxd = max(0 , maxd); cout << maxd << endl; } return 0;}
0 件のコメント:
コメントを投稿