暂存一篇未完成程序

#include<bits/stdc++.h>

using namespace std;

int n, ans, tot = 0;
int man_need[20];
int hire, employ, fire;

int main() {
    cin >> n;
    cin >> hire >> employ >> fire;
    for (int i = 1; i <= n; i++) {
        cin >> man_need[i];
        ans += man_need[i] * employ;
    }
    tot = man_need[1];
    ans += man_need[1] * hire;
    cout << ans << endl;
    for (int i = 2; i <= n; i++) {
        if (man_need[i] >= tot) {
            ans += (man_need[i] - tot) * hire + man_need[i] * employ;
            tot = man_need[i];
            cout << i << " " << tot << " " << ans << endl;
        }
        else if (man_need[i] < tot) {
                for (int j = 1; j <= n; j++)
                    if (man_need[i + j] > man_need[i]){
                        int gun = tot - man_need[i];
                        cout << j << " " << gun << endl;
                        int extra = gun * fire + (man_need[i + j] - man_need[i]) * hire;
                        int paid = j * employ;
                        if (extra < paid){
                            ans += gun * fire;
                            tot = man_need[i];
                        }
                        else ans += gun * employ;
                        break;
                    }
                    cout << i << " " << tot << " " << ans << endl;
            }
        //cout << i << " " << tot << endl; 
    }
    cout << ans << endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/sun915/p/9508242.html