2009-01-07
SRM379 Div1 Easy: SellingProducts
サンプルケースが親切
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define rep(var,n) for(int var=0;var<(n);var++)
class SellingProducts {
public:
int optimalPrice(vector<int> price, vector<int> cost) {
int n=sz(price);
vector<pair<int,int> > pc(n);
rep(i,n){ pc[i]=make_pair(price[i],cost[i]);}
sort(all(pc));
int summax=0, the_price=0;
rep(i,n){
int p=pc[i].first;
int sum=0;
for(int j=i;j<n;j++){
int d=(p - pc[j].second);
if(d>0) sum+=d;
}
if(sum>0){
if(sum==summax) ;
if(sum>summax){
summax=sum;
the_price=p;
}
}
}
return the_price;
}
};
いきなりコーディングしてるけどちゃんとまとめてからにした方がいい。却って時間をロスしている。(199.45点だったか)
コメント
トラックバック - https://topcoder-g-hatena-ne-jp.jag-icpc.org/n4_t/20090107