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 numbersdj (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 110 20 1510 20 3050 70 60Sample Output
3 2 1SourceNortheastern Europe 2007, Northern Subregion思路:首先根据村庄离A的距离和单位路程的花费,以及当地猪肉的价格,我们可以把到达每一个村庄卖猪单位重量赚的钱算出来。然后,按收益降序排列,再把猪的重量降序排序,这时,根据排序不等式,就可以达到最大盈利了。维基百科——排序不等式完整代码:
01./*32ms,216KB*/02.03.#include <cstdio>04.#include <algorithm>05.using namespace std;06.typedef long long ll;07.08.struct Node09.{10.ll value;11.int position;12.bool operator < (const Node a) const13.{14.return value > a.value;15.}16.} weight[1010], earn[1010];17.18.ll dis[1010];19.int ans[1010];20.21.int main(void)22.{23.int n;24.ll t;///单位运费25.while (~scanf("%d%lld", &n, &t))26.{27.for (int i = 1; i <= n; i++)28.{29.scanf("%lld", &weight[i].value);30.weight[i].position = i;31.}32.for (int i = 1; i <= n; i++)33.scanf("%lld", &dis[i]);34.for (int i = 1; i <= n; i++)35.{36.ll x;37.scanf("%lld", &x);38.earn[i].value = x - dis[i] * t;39.earn[i].position = i;40.}41.sort(weight + 1, weight + 1 + n);42.sort(earn + 1, earn + 1 + n);43.for (int i = 1; i <= n; i++)44.ans[earn[i].position] = weight[i].position;45.for (int i = 1; i < n; i++)46.printf("%d ", ans[i]);47.printf("%d ", ans[n]);48.}49.return 0;50.}