fork(2) download
  1. #include <iostream>
  2. #include <utility>
  3. #include <queue>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. typedef long long ll;
  9.  
  10. int main()
  11. {
  12. ios::sync_with_stdio(false); cin.tie(0);
  13.  
  14. int cases;
  15. cin >> cases;
  16. for (int testCase = 1; testCase <= cases; testCase++)
  17. {
  18. int laundries, washingMachines, dryers, dryTime;
  19. cin >> laundries >> washingMachines >> dryers >> dryTime;
  20.  
  21. vector<ll> washDurations(washingMachines);
  22. vector<ll> laundryFinishTime(laundries);
  23. priority_queue< pair<ll, int> > washFinishTimes;
  24. for (int washingMachine = 0; washingMachine < washingMachines; washingMachine++)
  25. {
  26. ll washDuration;
  27. cin >> washDuration;
  28.  
  29. washDurations[washingMachine] = washDuration;
  30.  
  31. auto washMachineFinishTime = make_pair(-washDuration, washingMachine);
  32. washFinishTimes.push(washMachineFinishTime);
  33. }
  34.  
  35. int dryersUnderUse = 0;
  36. for (int laundry = 0; laundry < laundries; laundry++)
  37. {
  38. auto bestWashMachineFinishTime = washFinishTimes.top();
  39. washFinishTimes.pop();
  40.  
  41. ll washFinishTime = -bestWashMachineFinishTime.first;
  42. int washingMachine = bestWashMachineFinishTime.second;
  43. ll nextWashFinishTime = washFinishTime + washDurations[washingMachine];
  44. washFinishTimes.push(make_pair(-nextWashFinishTime, washingMachine));
  45.  
  46. laundryFinishTime[laundry] = washFinishTime + dryTime;
  47. if (dryersUnderUse < dryers)
  48. {
  49. dryersUnderUse++;
  50. }
  51. else
  52. {
  53. int firstLaundryToFinishDrying = laundry - dryersUnderUse;
  54. ll currentLaundryDryingStartTime = laundryFinishTime[firstLaundryToFinishDrying];
  55. ll currentLaundryWaitTimeToStartDrying = currentLaundryDryingStartTime - washFinishTime;
  56.  
  57. if (currentLaundryWaitTimeToStartDrying > 0)
  58. laundryFinishTime[laundry] += currentLaundryWaitTimeToStartDrying;
  59. }
  60. }
  61.  
  62. int lastLaundry = laundries - 1;
  63. cout << "Case #" << testCase << ": " << laundryFinishTime[lastLaundry] << "\n";
  64. }
  65. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:31:18: error: 'washMachineFinishTime' does not name a type
             auto washMachineFinishTime = make_pair(-washDuration, washingMachine);
                  ^
prog.cpp:32:34: error: 'washMachineFinishTime' was not declared in this scope
             washFinishTimes.push(washMachineFinishTime);
                                  ^
prog.cpp:38:18: error: 'bestWashMachineFinishTime' does not name a type
             auto bestWashMachineFinishTime = washFinishTimes.top();
                  ^
prog.cpp:41:34: error: 'bestWashMachineFinishTime' was not declared in this scope
             ll washFinishTime = -bestWashMachineFinishTime.first;
                                  ^
stdout
Standard output is empty