uva 11790 Murcia’s Skyline Solution
uva 11790 Murcia’s Skyline Solution
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
int main() {
vector<int> height, width, inc, dec;
int i, j, test_case, n, x,max_i,max_d,cas=1;
cin >> test_case;
while (test_case--){
cin >> n;
height.clear();
width.clear();
inc.clear();
dec.clear();
for (i = 0; i < n; i++){
cin >> x;
height.push_back(x);
}
for (i = 0; i < n; i++){
cin >> x;
width.push_back(x);
}
inc.push_back(width[0]);
dec.push_back(width[0]);
max_i = max_d = width[0];
for (i = 1; i < n; i++){
inc.push_back(width[i]);
dec.push_back(width[i]);
if (max_i<width[i])
max_i = width[i];
if (max_d<width[i])
max_d = width[i];
for (j = 0; j < i; j++){
if (height[i] > height[j] && inc[j] + width[i]>inc[i]){
inc[i] = inc[j] + width[i];
if (max_i < inc[i])
max_i = inc[i];
}
else if (height[i] == height[j] && inc[j]>inc[i]){
inc[i] = inc[j];
if (max_i < inc[i])
max_i = inc[i];
}
if (height[i] < height[j] && dec[j] + width[i]>dec[i]){
dec[i] = dec[j] + width[i];
if (max_d < dec[i])
max_d = dec[i];
}
else if (height[i] == height[j] && dec[j]>dec[i]){
dec[i] = dec[j];
if (max_d < dec[i])
max_d = dec[i];
}
}
}
if (max_i < max_d)
cout << "Case " << cas++ << ". Decreasing (" << max_d << "). Increasing (" << max_i << ")." << endl;
else
cout << "Case " << cas++ << ". Increasing (" << max_i << "). Decreasing (" << max_d << ")." << endl;
}
return 0;
}
Comments
Post a Comment