Untitled

mail@pastecode.io avatar
unknown
c_cpp
23 days ago
1.2 kB
20
Indexable
Never
#include <bits/stdc++.h>

using namespace std;

int main() {
        int a[] = {100, 1, 100, 1};
        int arr[5][3];

        for (int i = 4; i >= 0; i--) {
                for (int j = 2; j >= 0; j--) {
                        if (i == 4)
                                arr[i][j] = 0;
                        else if (j == 2)
                                arr[i][j] = arr[i + 1][0];
                        else
                                arr[i][j] = max(arr[i + 1][0], a[i] + arr[i + 1][j + 1]);
                }
        }

        int max_val = arr[0][0];
        cout << "max salary: "<< max_val << endl;

        int i = 0;
        int j = 0;
        while (max_val) {
                if (j == 2)
                        i++;
                else if (arr[i + 1][0] >= a[i] + arr[i + 1][j + 1]) {
                        i++;
                        j = 0;
                }
                else if (arr[i + 1][0] < a[i] + arr[i + 1][j + 1]) {
                        cout << i << " ";
                        max_val -= a[i];
                        i++;
                        j++;
                }
        }

        cout << endl;
}
Leave a Comment