传送门:http://gdutcode.sinaapp.com/problem.php?cid=1057&pid=7
题解:
实现代码;
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN=1000010; int a[MAXN]; int main(){ int T; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); long long ans=0; for(int i=0;i<n&&a[i]<=ans+1;i++) ans+=a[i]; cout<<ans<<endl; } }