Submission #1188687

#TimeUsernameProblemLanguageResultExecution timeMemory
1188687sonyaHappiness (Balkan15_HAPPINESS)C++20
30 / 100
2095 ms5704 KiB
#include "happiness.h" #include <set> #include <algorithm> using namespace std; multiset<long long> coins; long long total_sum = 0; bool is_currently_happy() { long long reachable = 0; for (long long coin : coins) { if (coin > reachable + 1) return false; reachable += coin; } return true; } bool init(int coinsCount, long long maxCoinSize, long long coinsArray[]) { coins.clear(); total_sum = 0; for (int i = 0; i < coinsCount; ++i) { coins.insert(coinsArray[i]); total_sum += coinsArray[i]; } return is_currently_happy(); } bool is_happy(int event, int coinsCount, long long coinsArray[]) { if (event == -1) { // Remove coins (shopping) for (int i = 0; i < coinsCount; ++i) { auto it = coins.find(coinsArray[i]); if (it != coins.end()) { coins.erase(it); total_sum -= coinsArray[i]; } } } else if (event == 1) { // Add coins (wage) for (int i = 0; i < coinsCount; ++i) { coins.insert(coinsArray[i]); total_sum += coinsArray[i]; } } return is_currently_happy(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...