POJ 3544 Journey with Pigs

Source: Internet
Author: User
Tags integer numbers

Journey with Pigs
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 3004 Accepted: 922

Description

Farmer John had a pig farm near town a. He wants to visit him friend living in town B. During This journey he'll 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 is 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 has different weights. Transporting one kilogram of pork per one kilometer of the road needs T rubles for addition fuel.

Help John decide, the which pig to the sell in the 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 F Rom 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 is numbered from 1 in the order they is listed in the input file.

Sample Input

3 110 20 1510 20 3050 70 60

Sample Output

3 2 1

Ideas:
The problem is that every pound of pork is sold to the profit of the J Village: Pork unit Price-fare per unit * distance; the first line according to the quality of pigs from small to large number of orders; the second line is based on the number of profit from small to large;
The two lines multiply each other by multiplying all the product's and having such a law: the inverse product and the <= and the <= sequence product and (this is a greedy thought).
The steps are as follows:
Step1: Calculates the profit per kilo of pork sold to the J village according to the input (pork unit price-fare * distance).
Step2: The profits of each pound of pork are sold to the first village of J and the quality of each pig is sorted from small to large, then the corresponding position of the pig is sold to the corresponding location number of the village.
1#include <iostream>2#include <cstdio>3#include <algorithm>4 #defineLL Long Long5 using namespacestd;6 7typedefstruct{8 LL value;9     intpostion;Ten }node; One  ANode weight[1005], earn[1005]; -  - BOOLCMP (Node A, Node B) { the     returnA.value <B.value; - } -  - intMain () { +     intn, I; - LL t; +      while(SCANF ("%d%lld", &n, &t)! =EOF) { A          for(i =1; I <= N; i++){ atscanf"%lld", &weight[i].value); -Weight[i].postion =i; -         } -LL dis[1005]; -          for(i =1; I <= N; i++){ -scanf"%lld", &dis[i]); in         } -  to          for(i =1; I <= N; i++){ + LL x; -scanf"%lld", &x); theEarn[i].value = x-dis[i] *T; *Earn[i].postion =i; $         }Panax Notoginseng  -Sort (weight +1, weight + n +1, CMP); theSort (Earn +1, Earn + N +1, CMP); +  A         intans[1005]; the  +          for(i =1; I <= N; i++) -Ans[earn[i].postion] =weight[i].postion; $  $          for(i =1; I < n; i++) -printf"%d", Ans[i]); -printf"%d\n", Ans[n]); the     } -     return 0;Wuyi}

POJ 3544 Journey with Pigs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.