#include <bits/stdc++.h> //void converT using namespace std; int main() { //cout << __builtin_popcount(4) << endl; int n; int pomx; long long m; scanf("%d%lld", &n, &m); int t[n]; long long mx = LLONG_MIN; for(int i = 0; i < n; ++i){ scanf("%d", &t[i]); } int ile = 0; for(int i = n-1; i <= m; ++i){ ile = 0; int p = 0; for(int j = n-1; j >=0; --j){ //cout<<t[j]<<" "<<j<<endl; pomx = __builtin_popcount(i-p); ile += t[j] * (pomx); p++; } // cout<<ile<<endl; if(mx < ile) mx = ile; } //cout<<mx<<endl; printf("%lld", mx); 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 | #include <bits/stdc++.h> //void converT using namespace std; int main() { //cout << __builtin_popcount(4) << endl; int n; int pomx; long long m; scanf("%d%lld", &n, &m); int t[n]; long long mx = LLONG_MIN; for(int i = 0; i < n; ++i){ scanf("%d", &t[i]); } int ile = 0; for(int i = n-1; i <= m; ++i){ ile = 0; int p = 0; for(int j = n-1; j >=0; --j){ //cout<<t[j]<<" "<<j<<endl; pomx = __builtin_popcount(i-p); ile += t[j] * (pomx); p++; } // cout<<ile<<endl; if(mx < ile) mx = ile; } //cout<<mx<<endl; printf("%lld", mx); return 0; } |