# Codeforces 754D Fedor and coupons (priority queue)

Source: Internet
Author: User
Tags cmath

Test instructions: given n coupons, each has a certain range of concessions, and then to choose K Zhang, to ensure that K Zhang Common preferential range the largest.

First, all coupons are sorted by the left endpoint, then a priority queue with a capacity of k is maintained, the minimum value in the priority queue is updated each time, and the current right endpoint is

The distance between them. The priority queue is just as good as storing the right endpoint.

The code is as follows:

#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < cmath> #include <stack> #include <sstream> #include <unordered_map> #include <unordered_set > #define DEBUG () puts ("++++"), #define FREOPENR freopen ("In.txt", "R", stdin) #define FREOPENW freopen ("OUT.txt", "W", STDOUT) using namespace Std;typedef long long ll;typedef unsigned long long ull;typedef pair<int, int> p;const int in F = 0x3f3f3f3f;const LL LNF = 1LL << 60;const Double inf = 0x3f3f3f3f3f3f;const double PI = ACOs ( -1.0); const DOUBLE EPS = 1e-8;const int maxn = 3e5 + 5;const int mod = 2000;const int dr[] = {-1, 1, 0, 0};const int dc[] = {0, 0, 1, -1};con St Char *de[] = {"0000", "0001", "0010", "0011", "0100", "01"0110", "0111", "" "," "1001", "1010", "1011", "1100", "1101", "1110", "1111"};int N, m;const int mon[] = {0, 31, 28 ,,,,,,,,,,,,,,,,,,,,,,,, 31};const int monn[] = {0, ~, ~,------ OL is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;}    struct node{int L, r, id;    BOOL operator < (const Node &p) const{return L < P.L; }}; Node A[maxn];int Main () {while (scanf ("%d%d", &n, &m) = = 2) {for (int i = 0; i < n; ++i) {s            CANF ("%d%d", &AMP;A[I].L, &AMP;A[I].R);        A[i].id = i + 1;        } sort (A, a + N);        Priority_queue<int, Vector<int>, greater<int> >pq;        int ans = 0;        int t = 0;            for (int i = 0; i < n; ++i) {Pq.push (A[I].R);            if (Pq.size () > M) pq.pop ();            int tmp = Pq.top ()-A[I].L + 1; if (pq.size () = = m && ans <TMP) {ans = tmp;            t = A[I].L;        }} printf ("%d\n", ans);            if (!ans) {printf ("1");            for (int i = 2; I <= m; ++i) printf ("%d", I);        Continue            } else{int cnt = 0;  for (int i = 0; i < n && m; ++i) if (a[i].l <= t && a[i].r >= T + ans-1) {if (CNT)                Putchar (");                printf ("%d", a[i].id);                --m;            ++cnt;    }} printf ("\ n"); } return 0;}

Codeforces 754D Fedor and coupons (priority queue)

Related Keywords:

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.