Simple sorting and use long to avoid integer overflow
\r\njava []\r\nclass Solution {\r\n    public int maxScore(int[] nums) {\r\n     Arrays.sort(nums);\r\n    if(nums.length>1) reverse(nums);\r\n       long x=0;\
\r\n```java []\r\nclass Solution {\r\n    public int maxScore(int[] nums) {\r\n     Arrays.sort(nums);\r\n    if(nums.length>1) reverse(nums);\r\n       long x=0;\r\n     int c=0;\r\n     for(int i=0;i<nums.length;i++){\r\n        \r\n         x+=nums[i];\r\n    //System.out.println(x+" "+nums[i]);\r\n         if(x<=0)return (c);\r\n         else c++;\r\n        // c++;\r\n       \r\n           \r\n     }   \r\n     if(x>0)return c;  \r\n     return 0;\r\n    }\r\n    public void reverse(int[]nums){\r\n        int s=0;\r\n        int e=nums.length-1;\r\n        while(s<=e){\r\n          int t=nums[s];\r\n          nums[s]=nums[e];\r\n          nums[e]=t;\r\n            s++;\r\n            e--;\r\n        }\r\n    }\r\n}\r\n```
['Java']