Bzoj1572: [usaco 2009 Open] Work Arrangement job

Source: Internet
Author: User
1572: [usac2009 open] Job Schedule jobtime limit: 10 sec memory limit: 64 MB
Submit: 775 solved: 337
[Submit] [Status] Description

Farmer John has a lot of work to do !!!!!!!! To make the farm run efficiently, he must make money by his work. Each job takes one unit of time. His business day starts from and has 1000000000 unit time (!). At any time, he can select numbers 1 ~ N (1 <= n <= 100000. Because he can only do one job per unit time, and each job has another deadline, it is difficult for him to have time to complete all n jobs, although it is still possible. For job I, there is an end time d_ I (1 <= d_ I <= 1000000000). If he can finish the job, then he can make a profit for p_ I (1 <= p_ I <= 1000000000 ). what is the maximum profit that FJ can earn under the given work profit and deadline? The answer may be a 32-bit integer.

Input

Row 1st: an integer N. 2nd ~ N + 1 row: line I + 1 has two integers separated by spaces: d_ I and p_ I.

Output

Output a row with an integer representing the maximum profit value.

Sample input3
2 10
1 5
1 7

Sample output17

Hint

 

Complete 1st jobs (3rd) in 2nd units of time, and then complete 1st jobs () in units of time to maximize profits

 

Source

Gold

Question: Work Arrangements = enhanced version of the hamster game (but the solution is the same, the data of the hamster game is too weak) = I checked it for an hour ...... Code:
 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<iostream> 7 #include<vector> 8 #include<map> 9 #include<set>10 #include<queue>11 #define inf 100000000012 #define maxn 100000+100013 #define maxm 500+10014 #define eps 1e-1015 #define ll long long16 using namespace std;17 inline int read()18 {19     int x=0,f=1;char ch=getchar();20     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}21     while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}22     return x*f;23 }24 priority_queue<int,vector<int> >q;25 struct rec{int x,y;}a[maxn];26 bool cmp(rec a,rec b)27 {28     return a.x<b.x;29 }30 int main()31 {32     freopen("input.txt","r",stdin);33     freopen("output.txt","w",stdout);34     int n=read();35     for(int i=1;i<=n;i++)36     {37         a[i].x=read();a[i].y=read();38     }39     sort(a+1,a+n+1,cmp);40     //for(int i=1;i<=n;i++)cout<<i<<‘ ‘<<a[i].x<<‘ ‘<<a[i].y<<endl;41     int time=inf,i=n;ll ans=0;42     while(time)43     {44         while(a[i].x<time)45         {46             if(q.empty())time=a[i].x;47             else 48             {49                 ans+=q.top();q.pop();time--;50                 //cout<<ans<<‘ ‘<<q.top()<<‘ ‘<<a[i].x<<‘ ‘<<i<<endl;51             }52         }53         q.push(a[i].y);54         while(a[i].x==a[i-1].x)q.push(a[--i].y);55         i--;56     }57     printf("%lld\n",ans);58     return 0;59 }
View code

It turned out to be rank3 on bzoj. I thought I was always behind the status because my algorithm was not good enough and now I found that the language problem was 2333...

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.