3 solutions
-
3
#include<iostream> #include<queue> #include<stack> #include<math.h> #include<string.h> #include<algorithm> using namespace std; const int maxn=1e5+10; int number[maxn]; int main(){ int n; scanf("%d", &n); while(n--){ int m; scanf("%d", &m); for(int i=0;i<m;i++){ scanf("%d", &number[i]); } int ans=0,k; while(m>1){ sort(number+ans,number+m); for(int i=ans;i<m;i++){ if(number[i]==0){ ans++; }else{ break; } } if(ans>0){ ans--; } k=ans; for(int i=k;i<m-1;i++){ number[i]=number[i+1]-number[i]; } m--; } printf("%d\n", number[ans]); } }
Information
- ID
- 817
- Time
- 2000ms
- Memory
- 256MiB
- Difficulty
- 9
- Tags
- # Submissions
- 316
- Accepted
- 25
- Uploaded By