Checklist
Make sure to read all of How to ask for help on a problem before asking for help.
Problem Info
Contaminated Milk: USACO
Question
Include a specific question if you have one.
What I’ve Tried
I made a program. I looked at the test cases but they still said I was wrong.
My Work
#include <string>
#include <cstdio>
#include <iostream>
#include <map>
using namespace std;
struct event {
int t, p, m;
};
struct sickEvent {
int p, t;
};
int main() {
freopen("badmilk.in", "r", stdin);
freopen("badmilk.out", "w", stdout);
// n = #people, m = #milks, d = milkDrinking, s = sickpepple
int n, m, d, s, temp;
cin >> n >> m >> d >> s;
// Creates both arrays and puts the correct items in them.
event drinking[d];
for(int i = 0; i < d; i++){
cin >> temp;
drinking[i].p = temp;
cin >> temp;
drinking[i].m = temp;
cin >> temp;
drinking[i].t = temp;
}
sickEvent sick[s];
for(int i = 0; i < s; i++){
cin >> temp;
sick[i].p = temp;
cin >> temp;
sick[i].t = temp;
}
// Find out which milks cannot be bad.
int possibleMilks, maxSick, currentSick;
bool possible, milksDrank[m];
possibleMilks = 0;
maxSick = 0;
for(int i = 0; i < m; i++){
milksDrank[i] = true;
}
map<int, int> possibleMilksDrank;
// Loop through each milk type.
for(int i = 0; i < m; i++){
currentSick = 0;
possible = true;
// Loop through each person who got sick to see whether they drank the milk before
for(int j = 0; j < s; j++){
// Check if they drank that milk
for(int ii = 0; ii < d; ii++){
if(drinking[ii].p == sick[j].p && drinking[ii].m == i+1 && drinking[ii].t >= sick[j].t){
possible = false;
}
}
}
possibleMilksDrank.clear();
// If it can be it, then check how much medicine we need
if(possible == true){
for(int j = 0; j < d; j++){
if(drinking[j].m == i+1){
possibleMilksDrank[drinking[j].p]=0;
}
}
currentSick = possibleMilksDrank.size();
if(currentSick > maxSick){
maxSick = currentSick;
}
}
}
cout << maxSick;
}
basically do what they did in the answer explanation. USACO