#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { long long unsigned int n = 0; vector<long long unsigned int> w; vector<long long unsigned int> rp; long long unsigned int d = 0; long long unsigned int suma = 0; long long unsigned int temp = 0; long long unsigned int b = 0; cin>>n; for(int i=0; i<n; i++) { cin>>d; w.push_back(pow(2,d)); suma += w[i]; } sort(w.begin(),w.end()); while(temp <= suma) { b++; temp = pow(2,b); } b -= 1; cout<<b<<endl; return 0; }
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 | #include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { long long unsigned int n = 0; vector<long long unsigned int> w; vector<long long unsigned int> rp; long long unsigned int d = 0; long long unsigned int suma = 0; long long unsigned int temp = 0; long long unsigned int b = 0; cin>>n; for(int i=0; i<n; i++) { cin>>d; w.push_back(pow(2,d)); suma += w[i]; } sort(w.begin(),w.end()); while(temp <= suma) { b++; temp = pow(2,b); } b -= 1; cout<<b<<endl; return 0; } |