Wrong answer on test 2 for: https://codeforces.net/contest/1282/problem/C

Revision en1, by saiyaman_098, 2019-12-27 17:21:12

Hi,

I have submitted my solution which I believe is correct, but is failing on test 2. I don't see any reason why the logic is wrong. Can anyone please help me debug it ?

My code is:

#include <bits/stdc++.h>
using namespace std;

bool custom_sort(pair<int,int> a, pair<int, int> b) {
    return a.second < b.second;
}
int main() {
	// your code goes here
	int m;
	cin>>m;
	while(m--) {
	    int n,T,a,b;
	    cin>>n>>T>>a>>b;
	    vector<int> easyOrHard;
	    vector<pair<int,int>> problemInfo;
	    int totalEasyProblems = 0;
	    int i;
	    for(i=0;i<n;i++) {
	        int temp;
	        cin>>temp;
	        easyOrHard.push_back(temp);
	        if(temp == 0) {
	            totalEasyProblems+=1;
	        }
	    }
	    for(i=0;i<n;i++) {
	        int temp;
	        cin>>temp;
	        problemInfo.push_back(make_pair(easyOrHard[i], temp));
	    }
	    sort(problemInfo.begin(), problemInfo.end(),custom_sort);
	    int res = 0, currTime = 0, problemsSolvedSoFar = 0;
	    int easyProblemsEncountered = 0;
	    int easyProblemsSolvedSoFar = 0;
	    bool zeroForWholeExam = false;
	    i = 0;
	    while(i<n){
	        if(problemInfo[i].first == 0) {
	            easyProblemsEncountered+=1;
	            if(easyProblemsEncountered <= easyProblemsSolvedSoFar) {
	                i++;
	                continue;
	            }
	        }
	        //If problem is mandatory to solve now
	        //Conditions to solve current problem
	        if(problemInfo[i].second <= currTime 
	        || easyProblemsSolvedSoFar == totalEasyProblems 
	        || problemInfo[i].second <= currTime + a) {
    	        int timeToSolve = problemInfo[i].first == 0 ? a : b;
	            if(currTime + timeToSolve > T) {
	                break;
	            } else {
	                currTime = currTime + timeToSolve;
	                problemsSolvedSoFar+=1;
	            }
	            if(problemInfo[i].first == 0) {
	                easyProblemsSolvedSoFar+=1;
	            }
	            i++;
	        } else {
	            //Entering here to solve an easy problem since we have time.
	            if(currTime + a > T) {
	                break;
	            } else {
	                currTime = currTime + a;
	                problemsSolvedSoFar+=1;
	                easyProblemsSolvedSoFar+=1;
	            }
                if(problemInfo[i].first == 0) {
                    i++;
                }
	        }
	        if(i == n || currTime < problemInfo[i].second) {
	            res = problemsSolvedSoFar;
	        }
	    }
	    cout<<res<<endl;
	}
	return 0;
}
Tags practice, #debug

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English saiyaman_098 2019-12-27 17:21:12 2731 Initial revision (published)