#include<bits/stdc++.h> using namespace std; vector<int> a; #define int long long bool wystarczy(int m){ int pre=0; int n = a.size(); for(int i=0; i<n; i++){ int aktu=-1; for(int j = 0; j<1000; j++){ if(pre + j > m) return 0; long long ile = (j*(j-1)*(j-2)/6) + j*(j-1)*(m-j)/2 + pre*j*(m-pre-j); //cout << j << " ile: "<< ile<<"\n"; if(ile>=a[i]){ aktu=j; break; } } pre+=aktu; } return 1; } void solve(){ int n; cin >> n; a.resize(n); for(int i=0; i<n; i++){ cin >> a[i]; } int l=0, r = 1e9; while(l<r){ int m = (l+r)/2; if(wystarczy(m)){ r = m; } else l = m+1; } cout << l <<"\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--){ solve(); } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #include<bits/stdc++.h> using namespace std; vector<int> a; #define int long long bool wystarczy(int m){ int pre=0; int n = a.size(); for(int i=0; i<n; i++){ int aktu=-1; for(int j = 0; j<1000; j++){ if(pre + j > m) return 0; long long ile = (j*(j-1)*(j-2)/6) + j*(j-1)*(m-j)/2 + pre*j*(m-pre-j); //cout << j << " ile: "<< ile<<"\n"; if(ile>=a[i]){ aktu=j; break; } } pre+=aktu; } return 1; } void solve(){ int n; cin >> n; a.resize(n); for(int i=0; i<n; i++){ cin >> a[i]; } int l=0, r = 1e9; while(l<r){ int m = (l+r)/2; if(wystarczy(m)){ r = m; } else l = m+1; } cout << l <<"\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); int t; cin >> t; while(t--){ solve(); } } |