[POJ - 2010] Moo University - Financial Aid (PQ)

Moo University - Financial Aid

Descriptions

Cows University: admissions milk, cows enrolled in C from N (N is an odd number) head. They are scored score_i, need tuition fees aid_i. We hope newborn funding required no more than F, while the highest median score. Seeking herein digits.

Input

* Line 1: three space-delimited integers N, C and F. 

* First 2..C + 1 line: two rows each separated by a space integers. The first is the CSAT scores calves;  the second integer is the amount of financial assistance required for the Mavericks 

Output

* Line 1: A single integer that can reach the maximum Bessie median scores. If there is not enough money receiving calf N outputs -1. 

Sample Input

3 5 70
30 25
50 21
20 20
5 18
35 30

Sample Output

35

Hint

Sample Output : If Bessie accepted fraction CSAT 5,35 and calf 50, the median total financial assistance required to 35. 18 + 30 + 21 = 69 <= 70. 
 
Topic Link
 
When the sum of the first cow tuition lower_i sorted by score, consider each cow as a median, a low score (in front of) the cattle's than its sum upper_i later. And a high score from the score to a low scan meet aid_i + lower_i + upper_i <= F the first solution is the optimal solution.
 
AC Code
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>1
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#defineLong Long LL
 #define INF 0x3f3f3f3f
 #define MEM (X, Y) Memset (X, Y, the sizeof (X))
 #define MAXN 100005
 #define P pair <int, int>
 the using  namespace STD; 
P A [MAXN]; 
int N, C, F.;
 // bovine i as median, lower [i] represents a fraction less than the sum of its bovine tuition 
int Lower [MAXN], Upper [MAXN];
 int main () 
{ 
    CIN >> N C >> >> F.;
     int Half = N / 2 ;
     for ( int I = 0 ; I <C; I ++ ) 
        CIN >> A [I] .first >> A [I] .second; //Score tuition 
    Sort (A, A + C); 
    { 
        // determined Lower [I] 
        int Total = 0 ; 
        The priority_queue < int > Q;
         for ( int I = 0 ; I <C; I ++ ) 
        { 
            Lower [I] = Q .size () == Half? Total: INF; 
            q.push (a [I] .second); 
            Total + = a [I] .second;
             IF (q.size ()> Half) 
            { 
                // remove a tuition highest 
                total- = q.top ();  
                q.pop ();
            }
        } 
    } 
    { 
        // determined Upper [I] 
        int Total = 0 ; 
        The priority_queue < int > Q;
         for ( int I = the C- . 1 ; I> = 0 ; i-- ) 
        { 
            Upper [I] = q.size ( ?) == Half total: INF; 
            q.push (a [I] .second); 
            total + = a [I] .second;
             IF (q.size ()> Half) 
            { 
                // remove a tuition highest 
                total - =  q.top ();
                q.pop ();
            }
        }
    }
    int ans;
    for(int i=C-1; i>=0; i--)
        if(a[i].second+lower[i]+upper[i]<=F)
        {
            ans=a[i].first;
            break;
        }
    cout<<ans<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/sky-stars/p/11345104.html
Aid