2017-01-08 USACO USACO 4.2 Job Processing #include <vector>#include <iostream>#include <fstream>#include <algorithm>#include <climits>using namespace std;int N, M1, M2;vector<int> va, vb, cost, ta, tb;void compute(const vector<int> &vec, vector<int> &table) { int size = (int)vec.size(); cost = vector<int>(size, 0); for (int i = 0; i < N; ++i) { int min = INT_MAX, index; for (int j = 0; j < size; ++j) { int delay = cost[j] + vec[j]; if (min <= delay) continue; min = delay; index = j; } cost[index] = min; table[i] = min; }}int main() { ifstream fin("job.in"); ofstream fout("job.out"); int ansA, ansB = INT_MIN; fin >> N >> M1 >> M2; va = vector<int>(M1, 0), vb = vector<int>(M2, 0); ta = vector<int>(N, 0), tb = vector<int>(N, 0); for (int i = 0; i < M1; ++i) fin >> va[i]; for (int i = 0; i < M2; ++i) fin >> vb[i]; compute(va, ta); compute(vb, tb); sort(ta.begin(), ta.end()); sort(tb.begin(), tb.end(), [] (int a, int b) { return a > b; }); ansA = ta[N - 1]; for (int i = 0; i < N; ++i) { ansB = std::max(ta[i] + tb[i], ansB); } fout << ansA << " " << ansB << endl; cout << ansA << " " << ansB << endl;} Newer USACO 4.3 Buy Low Older USACO 4.2 The Pefect Stall