Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NMAX 10
- struct Banc {
- int val, nr;
- } v[NMAX];
- int n, s, total;
- void read() {
- cin >> n;
- for (int i = 1; i <= n; i++) {
- cin >> v[i].val >> v[i].nr;
- total += v[i].val * v[i].nr;
- }
- cin >> s;
- }
- void bsort() {
- bool sorted = false;
- while (!sorted) {
- sorted = true;
- for (int i = 1; i < n; i++)
- if (v[i].val < v[i + 1].val) {
- sorted = false;
- swap(v[i], v[i + 1]);
- }
- }
- }
- void greedy() {
- int i = 1, nr;
- while (s > 0 && i <= n) {
- nr = 0;
- while (s - v[i].val >= 0 && nr <= v[i].nr) {
- s -= v[i].val;
- nr++;
- }
- cout << v[i].val << '*' << nr << endl;
- i++;
- }
- }
- int main() {
- read();
- if (total < s)
- return cout << "Imposibil!", 0;
- bsort();
- greedy();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement