codeforces 1282C. Petya and Exam (greedy)

Link: https: //codeforces.com/contest/1282/problem/C

Meaning of the questions: a man to take the exam, the exam only two questions, one is the simple questions, each question is time-consuming fixed a; the other is the difficult questions, each question is time-consuming fixed b, to ensure that b> a. Solve a problem score is 1. Rules written exam is not just questions etc., how much, to encourage an assignment in advance. If you do not have an assignment ahead of time, then there is a part of the title will be listed as "must-do problem", when the "must do question" in the subject will not be fully completed, this course even if 0; otherwise, the number of questions to get the same score, including the "must do" and "non-essential do".

The meaning of problems: It is clear meaning of the questions required by the title of "must do time" in ascending order up, then the greedy do, must do from the beginning of time traversing each question is. If the traverse to the i-th title, the current time is T, then T-1 if an assignment at a time, you first need to put in front of all the questions have to do done, assuming that this process took time Ti, then the rest of the T - Ti time, then we are greedy in the remaining time as much as possible to do first with the rest of the simple question, do puzzles, recorded at this time ans, continue through all the topics have to do time in the end, constantly updated ans maximum. The final ans is the answer

AC Code:

 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 #include<cstring>
 5 #include<cstdio>
 6 #include<algorithm>
 7 using namespace std;
 8 typedef long long ll;
 9 ll mod = 1e9+7;
10 const int maxn = 2e5+10;
11 struct node{
12     int dif;
13     int ti;
14 }g[maxn];
15 bool cmp(node a,node b){
16     if(a.ti !=b.ti ) return a.ti<b.ti ;
17     return a.dif <b.dif ; 
18 }
19 int main(){
20     int q;cin>>q;
21     while(q--){
22         ll n,t,a,b;
23         cin>>n>>t>>a>>b;
24         ll cnta = 0,cntb = 0;
25         for(int i = 1;i<=n;i++){
26             intTD; CIN >> Td;
 27              IF (TD == 0 ) CNTA ++ ;
 28              the else CNTB ++ ;
 29              G [I] .dif = TD;
 30          }
 31 is          for ( int I = . 1 ; I <= n-; I ++ ) {
 32              int T; CIN >> T;
 33 is              G [I] .TI = T;
 34 is          }
 35          Sort (G + . 1 , n-+ G + . 1 , CMP); // press time will do to sort 
36          G [n-+ . 1 ] .TI T + = . 1;
 37 [          LL ANS = 0 , C1 = 0 , C2 = 0 ; // C1 C2 count the number will do subject 
38 is          for ( int I = . 1 ; I <= n-+ . 1 ; I ++ ) {
 39              LL CUR = A * C1 * B + C2;
 40              LL time = G [I] .TI - . 1 - CUR; // will do the time taken for the subject 
41 is              IF (time> = 0 ) { // If there is extra time, as do more more simple questions, problems do 
42 is                  LL TA = min (Time / a, cnta- C1);
 43 is                  Time- TA * = a;
44                 ll tb = min(time/b,cntb-c2);
45                 ans = max(ans,c1+c2+ta+tb);
46             }
47             if(g[i].dif == 0) c1++;
48             else c2++;
49         }
50         cout<<ans<<endl;
51     }
52     return 0;
53 }

Guess you like

Origin www.cnblogs.com/AaronChang/p/12130163.html