题目连接:
Description
Limak is a little polar bear. He plays by building towers from blocks. Every block is a cube with positive integer length of side. Limak has infinitely many blocks of each side length.
A block with side a has volume a3. A tower consisting of blocks with sides a1, a2, ..., ak has the total volume a13 + a23 + ... + ak3.
Limak is going to build a tower. First, he asks you to tell him a positive integer X — the required total volume of the tower. Then, Limak adds new blocks greedily, one by one. Each time he adds the biggest block such that the total volume doesn't exceed X.
Limak asks you to choose X not greater than m. Also, he wants to maximize the number of blocks in the tower at the end (however, he still behaves greedily). Secondarily, he wants to maximize X.
Can you help Limak? Find the maximum number of blocks his tower can have and the maximum X ≤ m that results this number of blocks.
Input
The only line of the input contains one integer m (1 ≤ m ≤ 1015), meaning that Limak wants you to choose X between 1 and m, inclusive.
Output
Print two integers — the maximum number of blocks in the tower and the maximum required total volume X, resulting in the maximum number of blocks.
Sample Input
48
Sample Output
9 42
Hint
## 题意有一个人在玩堆积木的游戏,给你一个X,这个人会贪心选择一个最大的数,使得这个数a^3=p^3要么你就不使用它,使得当前剩余值等于p^3-1,因为只有这样你才用不上p然后dfs去处理就好了
代码
#includeusing namespace std;map >H;long long getmax(long long x){ if(x==1)return 1; long long l=1,r=100005,ans=1; while(l<=r) { long long mid = (l+r)/2LL; if(mid*mid*mid<=x)ans=mid,l=mid+1; else r=mid-1; } return ans;}pair solve(long long x){ if(x==0)return make_pair(0,0); if(H.count(x))return H[x]; auto &tmp = H[x]; long long p = getmax(x); tmp=solve(x-p*p*p); tmp.first++; tmp.second+=p*p*p; auto tmp2 = solve(p*p*p-1); tmp=max(tmp,tmp2); return tmp;}void QAQ(){ long long m;scanf("%lld",&m); pair ans=solve(m); cout< <<" "< <