• codeforces 589 G


    G - Hiring
    Time Limit:4000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u

    Description

    The head of human resources department decided to hire a new employee. He created a test exercise for candidates which should be accomplished in at most m working days. Each candidate has to pass this test exercise. During the j-th day a candidate is allowed to be in the office for at most tj units of time.

    Overall, n candidates decided to apply for the job and sent out their resumes. Based on data received the head has defined two parameters describing every candidate: di and ri. The parameter di is the time to get prepared for work which the i-th candidate spends each morning. This time doesn't depend on day. The parameter ri is the total working time needed for the i-th candidate to accomplish the whole test exercise.

    Thus the time spent in the office in the j-th day consists of di units of time to get prepared and some units of time to proceed with the exercise. A candidate can skip entire working day and do not come to the office. Obviously in this case he doesn't spend di units of time to prepare.

    To complete the exercise a candidate should spend exactly ri units of time working on the exercise (time to prepare is not counted here).

    Find out for each candidate what is the earliest possible day when he can fully accomplish the test exercise. It is allowed to skip working days, but if candidate works during a day then he must spend di units of time to prepare for work before he starts progressing on the exercise.

    Input

    The first line contains two integer numbers n,  m(1 ≤ n,  m ≤ 2·105) — the number of candidates and the maximum number of working days to do the test exercise.

    The second line contains m integer numbers t1, t2, ..., tm(1 ≤ tj ≤ 106) — the durations of working days in time units.

    The following n lines contain two integers each: di,  ri(0 ≤ di ≤ 106,  1 ≤ ri ≤ 106) — how much time in the beginning of a day is required for i-th candidate before he starts his work on the test exercise and how much time it is needed for him to accomplish this task.

    Output

    Output a sequence of n integer numbers b1, b2, ..., bn, where bi is the earliest day when the i-th candidate can finish the test exercise.

    In case the i-th candidate cannot finish the test exercise in m days output bi = 0.

    Days in this problem are numbered from 1 to m in the order they are given in the input.

    Sample Input

    Input
    3 3
    4 2 5
    1 3
    2 5
    3 4
    Output
    1 3 0 


    需要注意。。。对于d相同的可以在之前的基础上直接处理。。。
    不然可能tle..
      1 /*************************************************************************
      2     > File Name: code/hust/20151025/H.cpp
      3     > Author: 111qqz
      4     > Email: rkz2013@126.com 
      5     > Created Time: 2015年10月27日 星期二 19时30分28秒
      6  ************************************************************************/
      7 
      8 #include<iostream>
      9 #include<iomanip>
     10 #include<cstdio>
     11 #include<algorithm>
     12 #include<cmath>
     13 #include<cstring>
     14 #include<string>
     15 #include<map>
     16 #include<set>
     17 #include<queue>
     18 #include<vector>
     19 #include<stack>
     20 #include<cctype>
     21                  
     22 #define yn hez111qqz
     23 #define j1 cute111qqz
     24 #define ms(a,x) memset(a,x,sizeof(a))
     25 #define pb push_back
     26 using namespace std;
     27 const int dx4[4]={1,0,0,-1};
     28 const int dy4[4]={0,-1,1,0};
     29 typedef long long LL;
     30 typedef double DB;
     31 const int inf = 0x3f3f3f3f;
     32 const int N=5E4+7;
     33 
     34 int n,m,k;
     35 vector<int> adj[N];
     36 vector<pair< pair<int,int> ,int> > ans;
     37 int pa[N];
     38 int kt[N];
     39 bool spe[N];
     40 void init()
     41 {
     42     ms(spe,false);
     43     ms(pa,0);
     44     scanf("%d %d %d",&n,&m,&k);
     45     for ( int i = 0,u,v; i < m ; i++)
     46     {
     47     scanf("%d %d",&u,&v);
     48     adj[u].push_back(v);
     49     adj[v].push_back(u);
     50     }
     51 
     52     for ( int i = 0,u ; i < k ; i++)
     53     {
     54     scanf("%d",&u);
     55     spe[u] = true;
     56     }
     57 
     58 }
     59 
     60 void dfs( int u)
     61 {
     62  //   cout<<"u:"<<u<<endl;
     63     vector<int> tmp;
     64     tmp.clear();
     65 
     66     for ( int j = 0 ; j < adj[u].size(); j++)
     67     {
     68     int v =adj[u][j];
     69     if (pa[v]==0)
     70     {
     71         pa[v] =  u;
     72         dfs(v);
     73         if (kt[v]) tmp.push_back(kt[v]);
     74     }
     75     }
     76     while (tmp.size()>1)
     77     {
     78     int x1 = tmp.back();tmp.pop_back();
     79     int x2 = tmp.back(); tmp.pop_back();
     80 //    cout<<"x1:"<<x1<<" x2:"<<x2<<endl;
     81     ans.pb(make_pair(make_pair(x1,x2),u));
     82     }
     83     if (tmp.size()>0)
     84     {
     85     int x = tmp.back();tmp.pop_back();
     86 
     87 //    cout<<"x:"<<x<<endl;
     88     if (spe[u])
     89     {
     90         ans.push_back(make_pair(make_pair(x,u),u));
     91     }
     92     else kt[u] = x;
     93     }
     94     else 
     95     {
     96     if (spe[u]) kt[u] =  u;
     97     }
     98 }
     99 
    100 void solve()
    101 {
    102     for ( int i = 1 ; i <n+1 ; i++)
    103     if (!pa[i])
    104     {
    105         pa[i] = -1;
    106         dfs(i);
    107     }
    108 
    109     vector<int>p,q;
    110    // printf("%d
    ",ans.size());
    111       cout<<ans.size()<<endl;
    112     for ( int i = 0 ; i < ans.size(); i++)
    113     {
    114     int u = ans[i].first.first;
    115     int v = ans[i].first.second;
    116     int r = ans[i].second;
    117 //    cout<<"************************"<<endl;
    118 //    cout<<"u:"<<u<<" v:"<<v<<" r:"<<r<<endl;
    119 //    cout<<"************************"<<endl<<endl;
    120 
    121     p.clear();
    122     q.clear();
    123     while (u!=r)
    124     {
    125         p.push_back(u);
    126         u = pa[u];
    127     }
    128 
    129     while (v!=r)
    130     {
    131         q.push_back(v);
    132         v = pa[v];
    133     }
    134 
    135     //printf("%d ",p.size()+q.size());
    136     cout<<p.size()+q.size()<<" ";
    137     for ( int j = 0 ; j < p.size(); j++) printf("%d ",p[j]);
    138     printf("%d ",r);
    139     
    140     reverse(q.begin(),q.end());
    141     for ( int j = 0 ; j < q.size(); j++) printf("%d ",q[j]);
    142     puts("");    
    143     
    144     }
    145 }
    146 int main()
    147 {
    148   #ifndef  ONLINE_JUDGE 
    149    freopen("in.txt","r",stdin);
    150   #endif
    151    init();
    152    solve();
    153   
    154    
    155  #ifndef ONLINE_JUDGE  
    156   fclose(stdin);
    157   #endif
    158     return 0;
    159 }
    View Code


     
  • 相关阅读:
    【JLOI 2015】城池攻占
    【BalticOI 2004】Sequence
    罗马游戏
    《STL源码剖析》STL迭代器分类
    《Effective C++》模版与泛型编程
    《Effective C++》继承与面向对象设计
    《Effective C++》实现 章节
    [C++]const_cast,dynamic_cast,reinterpret_cast,static_cast转型
    [C++]default constructor默认构造函数
    [C++]union联合体总结
  • 原文地址:https://www.cnblogs.com/111qqz/p/4915557.html
Copyright © 2020-2023  润新知