zoukankan      html  css  js  c++  java
  • P2949 [USACO09OPEN]Work Scheduling G

    Aimee

    很水的题目

    很简单的反悔贪心,能干就干,干不了就把最小的扔掉

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<cstring>
    #include<queue>
    #define int long long
    using namespace std;
    priority_queue <int> q;
    int Aimee;
    int n;
    struct wor{
    	int ti;
    	int mo;
    } th[100001];
    int read(){
    	int f=1,ans=0;
    	char c;
    	c=getchar();
    	while(c!='-'&&(c<'0'||c>'9')){
    		c=getchar();
    	}
    	if(c=='-'){
    		f=-1;
    		c='0';
    	}
    	while(c>='0'&&c<='9'){
    		ans=(ans<<1)+(ans<<3)+c-'0';
    		c=getchar();
    	}
    	return ans*f;
    }
    bool cmp( wor x,wor y){
    	return x.ti<y.ti;
    }
    signed main(){
    	n=read();
    	for(int i=1;i<=n;++i){
    		th[i].ti=read();
    		th[i].mo=read(); 
    	}
    	sort(th+1,th+n+1,cmp);
    	for(int i=1;i<=n;++i){
    		q.push(-th[i].mo);
    		Aimee+=th[i].mo;
    		if(q.size()>th[i].ti){
    			Aimee+=q.top();
    			q.pop();
    		}
    	}
    	printf("%lld",Aimee); 
    	return 0;
    } 
    
  • 相关阅读:
    设计模式 23
    生活杂谈
    设计模式经典书籍
    ABP 样板开发框架系列
    关键字
    vs 2015
    优秀文章推荐
    Parallel 并行编程
    CSRF
    sql性能优化
  • 原文地址:https://www.cnblogs.com/For-Miku/p/13933986.html
Copyright © 2011-2022 走看看