2018 Team Training Game 15 (Question C: Frosh Week) (Sign-in)

Question C: Frosh Week

Time Limit: 4 Sec   Memory Limit: 128 MB
Commits: 145   Resolved: 63
[ Commit ][ Status ][ Discussion Board ][Assert By: admin ]

Topic description

Professor Zac is trying to finish a collection of tasks during the first week at the start of the term. He knows precisely how long each task will take, down to the millisecond. Unfortunately, it is also Frosh Week. Zac’s office window has a clear view of the stage where loud music is played. He cannot focus on any task when
music is blaring.
The event organizers are also very precise. They supply Zac with intervals of time when music will not be playing. These intervals are specified by their start and end times down to the millisecond.
Each task that Zac completes must be completed in one quiet interval. He cannot pause working on a task when music plays (he loses his train of thought). Interstingly, the lengths of the tasks and quiet intervals are such that it is impossible to finish more than one task per quiet interval!
Given a list of times ti (in milliseconds) that each task will take and a list of times Lj (in milliseconds) specifying the lengths of the intervals when no music is being played, what is the maximum number of tasks that Zac can complete?

enter

The first line of input contains a pair of integers n and m, where n is the number of tasks and m is the
number of time intervals when no music is played. The second line consists of a list of integers t1,t2,...,tn indicating the length of time of each task. The final line consists of a list of times L1,L2,... ,Lm indicating the length of time of each quiet interval when Zac is at work this week.
You may assume that 1≤n;m≤200,000 and 100,000≤ti,Lj≤199,999 for each task i and each quiet interval j.

output

Output consists of a single line containing a single integer indicating the number of tasks that Zac can accomplish from his list during this first week.

sample input

5 4
150000 100000 160000 100000 180000
190000 170000 140000 160000

Sample output

4 


is a very simple simulation question. At first I thought to save all the time, then sort, put the bigger ones in the front, and compare them. Although I was worried about the time, I saw that I still handed in the 4s, as expected. Orz

looks at it later, isn't it just the time range of 1e5 to 2e5, just use the value hash and run it again.

 1 #include<bits/stdc++.h>
 2  
 3 using namespace std;
 4  
 5 int task[100001];
 6 int work_num[100001];
 7 const int limit = 100000;
 8  
 9 int main()
10 {
11     int n,m;
12     scanf("%d%d",&n,&m);
13     int temp;
14     memset(task,0,sizeof(task));
15     memset(work_num,0,sizeof(work_num));
16     for(int i=0;i<n;i++)
17     {
18         scanf("%d",&temp);
19         task[temp-limit]++;
20     }
21     for(int i=0;i<m;i++)
22     {
23         scanf("%d",&temp);
24         work_num[temp - limit]++;
25     }
26     int ans = 0;
27     int cnt = 0;
28     for(int i=limit;i>=0;i--)
29     {
30         if(work_num[i])cnt+=work_num[i];
31         if(cnt != 0)
32         {
33             if(task[i])
34             {
35                 int minn = min(task[i],cnt);
36                 ans += minn;
37                 cnt -= minn;
38             }
39         }
40     }
41     printf("%d\n",ans);
42 }
43  
44 /**************************************************************
45     Problem: 5129
46     User: DP18
47     Language: C++
48     Result: 正确
49     Time:68 ms
50     Memory:2476 kb
51 ****************************************************************/
View Code

 



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324891866&siteId=291194637