Description
Farmer John has a pig farm near town A. He wants to visit his friend living in town B. During this journey he will visit n small villages so he decided to earn some money. He tooks n pigs and plans to sell one pig in each village he visits.
Pork prices in villages are different, in the j-th village the people would buy a pork at pj rubles per kilogram. The distance from town A to the j-th village along the road to town B is dj kilometers.
Pigs have different weights. Transporting one kilogram of pork per one kilometer of the road needs t rubles for addition fuel.
Help John decide, which pig to sell in each town in order to earn as much money as possible.
Input
The first line of the input file contains integer numbers n (1 ≤ n ≤ 1000) and t (1 ≤ t ≤ 109). The second line contains n integer numbers wi (1 ≤ wi ≤ 109) — the weights of the pigs. The third line contains n integer numbers dj (1 ≤ dj ≤ 109) — the distances to the villages from the town A. The fourth line contains n integer numbers pj (1 ≤ pj ≤ 109) — the prices of pork in the villages.
Output
Output n numbers, the j-th number is the number of pig to sell in the j-th village. The pigs are numbered from 1 in the order they are listed in the input file.
Sample Input
3 1 10 20 15 10 20 30 50 70 60
Sample Output
3 2 1
/*
Poj 3544 Journey with Pigs
将n头猪卖给n个村庄,猪重wi,每个村庄到起点的距离是dj,每斤猪肉在第j个村庄的单价是pj,每斤猪肉运输一个单位长度花费t元,为保证赚到最多的钱,该怎样分配?
输入n,t。接着输入,第一行为n个数表示猪的重量,第二行为n个数表示到村庄的距离,第三行为n个数表示每个村庄的猪肉价格。
输出n个数,第j个数表示出售到第j个村庄的猪的编号,每只猪的编号从1开始。
input
3 1
10 20 15
10 20 30
50 70 60
output
3 2 1
*/
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct village{
int n; //村庄编号;
long long d,p,m; //d为到该村庄的距离,p为该村庄的猪肉价格,m为每公斤猪肉获得的利润;
}va[3000];
struct pig{
int n; //猪的编号;
long long w; //猪的重量;
}pi[2000];
bool cmpp(pig a,pig b){ //排序规则:根据猪的重量从大到小;
return a.w > b.w;
}
bool cmpv(village a,village b){ //排序规则:根据每公斤猪肉可获得的利润从大到小;
return a.m >b.m;
}
int sel[1000];
int main(){
int n,t,i,j;
while(cin >>n >>t){
memset(sel,0,sizeof(sel));
for(i = 0;i < n;i++){ //输入第一行,每只猪的重量;
pi[i].n = i;
cin >>pi[i].w;
}
for(i = 0;i < n;i++){ //输入第二行,到每个村庄的距离;
va[i].n = i;
cin >>va[i].d;
}
for(i = 0;i <n;i++){ //输入第三行,每个村庄的猪肉价格,并计算到该村庄卖每公斤猪肉的利润;
cin >>va[i].p;
va[i].m = va[i].p - va[i].d*t;
}
sort(pi,pi+n,cmpp); //排序;
sort(va,va+n,cmpv);
for(i = 0;i <n;i++) //将重量重的猪卖到价格高的村庄,以此类推;
sel[va[i].n] = pi[i].n;
for(i = 0;i <n;i++){
cout <<sel[i]+1; //按顺序输出编号由小到大村庄所卖的猪的编号;
(i == n-1)?cout <<endl:cout <<" ";
}
}
return 0;
}