codeforces 589 G - Hiring(模拟?)

G - Hiring

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

Submit Status Practice CodeForces 589G

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 34 2 51 32 53 4

Output

1 3 0 

需要注意。。。对于d相同的可以在之前的基础上直接处理。。。不然可能tle..

  1 /*************************************************************************
  2     > File Name: code/hust/20151025/H.cpp
  3     > Author: 111qqz
  4     > Email: [email protected]
  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\n",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 }

				
时间: 2024-08-09 21:04:24

codeforces 589 G - Hiring(模拟?)的相关文章

Codeforces 48C The Race 模拟题

题目链接:点击打开链接 题意: 给定n个加油站,一辆车由A点跑到B点,每个100m有一个加油站,每开100m需要10升油. 在每个车站会检查一下油量,若车子若开不到下一个加油站则加x升油. 开始有x升油 下面给出加油的记录. 问下一次加油在哪一站.若答案唯一输出具体哪站. 油箱容量无限 思路: 水模拟.. #include <stdio.h> #include <string.h> #include <stdlib.h> #include <math.h>

CodeForces - 200DProgramming Language纯模拟

CodeForces - 200D Programming Language Time Limit: 2000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Submit Status Description Recently, Valery have come across an entirely new programming language. Most of all the language attracted h

codeforces 589 D - Boulevard

D - Boulevard Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589D Description Welcoming autumn evening is the best for walking along the boulevard and n people decided to do so. The bou

Codeforces 724 G Xor-matic Number of the Graph 线性基+DFS

G. Xor-matic Number of the Graph http://codeforces.com/problemset/problem/724/G 题意:给你一张无向图.定义一个无序三元组(u,v,s)表示u到v的(不一定为简单路径)路径上xor值为s.求出这张无向图所有不重复三元组的s之和.1≤n≤10^5,1≤m≤2*10^5. 想法: 如果做过[Wc2011 xor]这道题目(题解),那么问题变得简单起来了. ①假设我们钦定一个(u,v),设任意一条u->v的路径xor值为X,

codeforces 659 G. Fence Divercity 组合数学 dp

http://codeforces.com/problemset/problem/659/G 思路: f(i,0/1,0/1) 表示到了第i个,要被切的块开始了没有,结束了没有的状态的方案数 递推看代码: //File Name: cf659G.cpp //Author: long //Mail: [email protected] //Created Time: 2016年07月12日 星期二 12时40分28秒 #include <stdio.h> #include <string.

codeforces 614B(div.2) 模拟

模拟乘法 有毒的一题,各种细节..代码写得自己都不想看.. #include"cstdio" #include"queue" #include"cmath" #include"stack" #include"iostream" #include"algorithm" #include"cstring" #include"queue" #includ

CodeForces 1B. Spreadsheets(模拟)

题目链接:http://codeforces.com/problemset/problem/1/B B. Spreadsheets time limit per test 10 seconds memory limit per test 64 megabytes input standard input output standard output In the popular spreadsheets systems (for example, in Excel) the following

codeforces 589 I - Lottery(水)

I - Lottery Time Limit:2000MS     Memory Limit:524288KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 589I Description Today Berland holds a lottery with a prize — a huge sum of money! There are k persons, who attend the lottery

Codeforces #200(div.2) 模拟练习赛

A题: 题意:一行磁铁,同性相斥,找到这行磁铁可以分为多少块 思路:边读边计算,读到和上一次不一样的就加1(第一组数据特判) 手速题然而我没有把思路理清楚再写,比队友满了太多=_+. 代码: #include <set> #include <map> #include <cmath> #include <stack> #include <queue> #include <string> #include <vector>