tonfain

milkMeasurement_tonfaiv1

Dec 21st, 2022
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. struct ent{
  5. int day;
  6. int id;
  7. int change;
  8. };
  9.  
  10. bool compareDay(const ent& a, const ent& b){
  11. return a.day < b.day;
  12. }
  13.  
  14. int main(){
  15. ifstream fin("measurement.in");
  16. ofstream fout("measurement.out");
  17. int N, G;
  18. fin >> N >> G;
  19.  
  20. vector<ent> entries(N);
  21. vector<int> cowID;
  22. map<int, int> cowInfo;
  23. for(int i = 0; i<N; i++){
  24. fin >> entries[i].day >> entries[i].id >> entries[i].change;
  25. cowInfo.insert({entries[i].id, G});
  26. if(find(cowID.begin(), cowID.end(), entries[i].id) != cowID.end()){
  27. //cout << "found: " << entries[i].id << endl;
  28. }else{
  29. cowID.push_back(entries[i].id);
  30. //cout << "pushed back: " << entries[i].id << endl;
  31. }
  32.  
  33. //cout << entries[i].day << " " << entries[i].id << " " << entries[i].change << endl;
  34. }
  35. sort(entries.begin(), entries.end(), compareDay);
  36.  
  37. int ans = 0;
  38. int mx = G;
  39. int mx2 = 0;
  40. int recordHolder2 = 0;
  41. int recordHolder = 0;
  42. int currNumDisplay = 0;
  43. //cout << "cowID.size(): " << cowID.size() << endl;
  44. for(int i = 0; i<N; i++){
  45. int currId = entries[i].id;
  46. cowInfo[currId] += entries[i].change;
  47.  
  48. if(cowInfo[currId] > mx){
  49. mx2 = mx;
  50. mx = cowInfo[currId];
  51. //cout << "greater than max" << endl;
  52. currNumDisplay = 1;
  53. recordHolder2 = recordHolder;
  54. recordHolder = currId;
  55. ans++;
  56. continue;
  57. }else if(entries[i].change < 0 && currId == recordHolder){
  58. if(mx2 >= cowInfo[currId]){
  59. //currNumDisplay--;
  60. recordHolder = recordHolder2;
  61. mx = mx2;
  62. //ans++;
  63. }
  64. }
  65.  
  66. //int curMax = mx;
  67. int cnt = 0;
  68. for(int j = 0; j<cowID.size(); j++){
  69. if(cowInfo[cowID[j]] == mx){
  70. cnt++;
  71. }
  72. }
  73. //cout << "i = " << i << ", current max: " << mx << ", count: " << cnt << ", currently on display: " << currNumDisplay << endl;
  74.  
  75. if(cnt != currNumDisplay){
  76. ans++;
  77. currNumDisplay = cnt;
  78. }
  79.  
  80. //cout << "changed ID: " << currId << ", to " << cowInfo[currId] << endl;
  81.  
  82. //if(cowInfo[currId] > mx){
  83. //mx2 = mx;
  84. //mx = cowInfo[currId];
  85. //if(currId != recordHolder){
  86. //cout << "greater than max" << endl;
  87. //currNumDisplay = 1;
  88. //recordHolder2 = recordHolder;
  89. //recordHolder = currId;
  90. //ans++;
  91. //}
  92. //}else if(entries[i].change < 0 && currId == recordHolder){
  93. //if(mx2 >= cowInfo[currId]){
  94. //currNumDisplay--;
  95. //recordHolder = recordHolder2;
  96. //mx = mx2;
  97. //ans++;
  98. //}
  99. //}else if(entries[i].change > 0 && cowInfo[currId] == mx){
  100. //currNumDisplay++;
  101. //cout << "increase to become equal" << endl;
  102. //recordHolder = currId;
  103. //ans++;
  104. //}
  105. //cout << "currently on display: " << currNumDisplay << endl;
  106. }
  107. fout << ans << endl;
  108. }
  109.  
Advertisement
Add Comment
Please, Sign In to add comment