Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main() {
- int c;
- double n, item, price, sum = 0;
- cin >> n;
- cin >> c;
- double a[c][3];
- for (int i = 0; i < c; i++) {
- cin >> item;
- a[i][0] = item;
- cin >> price;
- a[i][1] = price;
- a[i][2] = price / item;
- }
- for (int i = 0; i < c - 1; i++) {
- for (int j = 0; j < c - i - 1; j++) {
- if (a[j][2] < a[j+1][2]) {
- double t = a[j+1][2];
- a[j+1][2] = a[j][2];
- a[j][2] = t;
- double t1 = a[j+1][0];
- a[j+1][0] = a[j][0];
- a[j][0] = t1;
- }
- }
- }
- for (int i = 0; ; i++) {
- if (n > a[i][0]) {
- sum += a[i][0] * a[i][2];
- n -= a[i][0];
- } else {
- sum += n * a[i][2];
- break;
- }
- }
- cout << sum;
- return 0;
- }
Add Comment
Please, Sign In to add comment