Poj 3618 registration

Source: Internet
Author: User

Token
Time Limit:1000 MS   Memory Limit:65536 K
Total Submissions:3826   Accepted:1850

Description

Bessie is traveling on a road teeming with interesting landmarks. The road is labeled just like a number line, and Bessie starts at the "origin "(X= 0). A totalN(1 ≤NLess than or equal to 50,000) landmarks are located at pointsX1,X2 ,...,XN(-100,000 ≤Xi≤ 100,000). Bessie wants to visit as your landmarks as possible before sundown, which occurs inT(1 ≤T≤ 1,000,000,000) minutes. She travels 1 distance unit in 1 minute.

Bessie will visit the landmarks in a particle order. since the landmarks closer to the origin are more important to Farmer John, she always heads for the unvisited landmark closest to the origin. no two landmarks will be the same distance away from the origin.

Help Bessie determine the maximum number of landmarks she can visit before the day ends.

Input

* Line 1: Two space-separated integers:TAndN
* Lines 2 ..N+ 1: LineI+ 1 contains a single integer that is the location ofITh landmark:Xi

Output

* Line 1: The maximum number of landmarks Bessie can visit.

Sample Input

25 510-38-71

Sample Output

4

QUESTION: Let's give you a bunch of points. Starting from the origin, the rule of the point is to give priority to the point closest to the origin. Ask the maximum number of points that can be reached in t seconds;


# Include <iostream> # include <algorithm> using namespace std; # define MAX 50000 + 5 struct point {int landmark, distance;} p [MAX]; bool cmp (point, point B) {if (. distance <B. distance) return true; return false;} int main () {int t, n; while (cin >>t> n) {for (int I = 0; I <n; I ++) {cin> p [I]. landmark; p [I]. distance = p [I]. landmark> 0? P [I]. landmark :(-p [I]. landmark);} sort (p, p + n, cmp);/* Testfor (int I = 0; I <n; I ++) cout <p [I]. landmark <"<p [I]. distance <endl; Test */int last = 0, I; for (I = 0; I <n; I ++) {int d = p [I]. landmark-last> 0? (P [I]. landmark-last) :( last-p [I]. landmark); if (t> = d) {t-= d; last = p [I]. landmark;} elsebreak;} cout <I <endl;} return 0 ;}



Poj 3618 registration

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.