fork(1) download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int test,parata,cook,rnk[10000],cnt,i;
  4. bool check(int t)
  5. {
  6. cnt=0;
  7. for(i=0;i<cook;i++)
  8. {
  9. cnt=cnt+((-1)+sqrt(1+8*t/rnk[i]))/2;
  10. if(cnt>=parata)
  11. return true;
  12. }
  13. return false;
  14. }
  15. int main()
  16. {
  17.  
  18. scanf("%d",&test);
  19. while(test--)
  20. {
  21. scanf("%d%d",&parata,&cook);
  22. for(i=0;i<cook;i++)
  23. cin>>rnk[i];
  24. int hi=10000000,lo=0,mid;
  25. while(hi>lo)
  26. {
  27. mid=(hi+lo)/2;
  28. if(check(mid))
  29. hi=mid;
  30. else
  31. lo=mid+1;
  32. }
  33. cout<<lo<<endl;
  34. }
  35. }
  36.  
Success #stdin #stdout 0s 2768KB
stdin
3
10
4 1 2 3 4
8
1 1
8
8 1 1 1 1 1 1 1 1
stdout
12
36
1