1 solutions
-
0
C++ :
#include <iostream> #include <algorithm> using namespace std; typedef struct tagSupply { int m_price; int m_amount; } Supply; int main() { int comp(const Supply& a, const Supply& b); int n = 0, m = 0; int nSum = 0; Supply* p = NULL; cin >>n >>m; p = new Supply[m]; for (int i = 0; i < m; ++i) { cin >>p[i].m_price >>p[i].m_amount; } sort(p, p+m, comp); int i = 0; while (n > 0) { if (n >= p[i].m_amount) { nSum += p[i].m_amount * p[i].m_price; n -= p[i].m_amount; } else { nSum += n * p[i].m_price; n = 0; } ++i; } cout <<nSum; delete []p; return 0; } int comp(const Supply& a, const Supply& b) { return a.m_price < b.m_price; }
- 1
Information
- ID
- 20033
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By