2 solutions
O(nlogn) \n\nclass Solution {\npublic:\n    bool asteroidsDestroyed(int m, vector<int>& asteroids) {\n        sort(asteroids.begin(),asteroids.end()); \n       
1. O(nlogn) \n```\nclass Solution {\npublic:\n    bool asteroidsDestroyed(int m, vector<int>& asteroids) {\n        sort(asteroids.begin(),asteroids.end()); \n        long long mass = m; \n        for(int a: asteroids){\n            if(mass<a)\n                return 0;\n            mass += a; \n        }\n        return true; \n    }\n};\n```\n2. O(n)\n```\nclass Solution {\npublic:\n    bool asteroidsDestroyed(int mass, vector<int>& asteroids) {\n        vector<int> count(1e5+1,0);\n        long long m = mass; \n        for(int a: asteroids) \n            count[a]++;\n        for(int i=1;i<1e5+1;i++){\n            if(count[i]){\n                if(m<i)\n                    return 0;\n                m += 1LL * count[i]*i;\n            }\n        }\n        return 1;\n    }\n};\n```
[]