HDU 4864 4std d

Source: Internet
Author: User

1. Be able to analyze the reasons for greed

2. Perform lower_bound in LV: because the time of the task is already sorted in ascending order, we should start from the smallest level for each time in the task,

Because there may be a relatively large LV behind the task;

3. lower_bound usage

4. Binary writing

5. Comparison function CMP


# Include <cstdio> # include <cstring> # include <iostream> # include <algorithm> # include <vector> # include <cmath> # include <queue> # include <stack> # include <map> # include <set> using namespace STD; # define CLR (x) memset (x, 0, sizeof (x) # define FP1 freopen ("in.txt", "r", stdin) # define fp2 freopen ("out.txt", "W", stdout) # define Pb push_back # define INF 0x3c3c3ctypedef _ int64 ll; const int maxn = 1e5 + 100; typedef struct NN {ll time, lv;} nn; nn task [maxn], Mac [maxn]; int n, m; Multiset <int> SS [150]; bool CMP (nn a, nn B) {if (. time> B. time) return true; else {if (. time = B. time) return. LV> B. LV; else return false;} int main () {// FP1; while (scanf ("% d", & N, & M) = 2) {for (INT I = 0; I <150; I ++) ss [I]. clear (); For (INT I = 1; I <= N; I ++) {scanf ("% i64d % i64d", & Mac [I]. time, & Mac [I]. LV); SS [Mac [I]. LV]. insert (MAC [I]. time) ;}for (INT I = 1; I <= m; I ++) {scanf ("% i64d % i64d", & task [I]. time, & task [I]. LV);} Sort (Task + 1, task + 1 + M, CMP); ll count = 0, sum = 0; For (INT I = 1; I <= m; I ++) {for (Int J = task [I]. LV; j <150; j ++) {If (ss [J]. size () = 0) continue; If (ss [J]. lower_bound (task [I]. time) = ss [J]. end () {continue;} else {count ++; Multiset <int >:: iterator it = ss [J]. lower_bound (task [I]. time); sum + = (task [I]. time * 500 + task [I]. LV * 2); SS [J]. erase (it); break ;}} printf ("% i64d % i64d \ n", Count, sum);} return 0 ;}



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.