Codeforces Round #356 (Div. 2) D. Bear and Tower of Cubes

185 篇文章 0 订阅
D. Bear and Tower of Cubes
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Examples
Input
48
Output
9 42
Input
6
Output
6 6
Note

In the first sample test, there will be 9 blocks if you choose X = 23 or X = 42. Limak wants to maximize X secondarily so you should choose 42.

In more detail, after choosing X = 42 the process of building a tower is:

  • Limak takes a block with side 3 because it's the biggest block with volume not greater than 42. The remaining volume is 42 - 27 = 15.
  • The second added block has side 2, so the remaining volume is 15 - 8 = 7.
  • Finally, Limak adds 7 blocks with side 1, one by one.

So, there are 9 blocks in the tower. The total volume is is 33 + 23 + 7·13 = 27 + 8 + 7 = 42.

题意:给你一个数n,让你找一个不超过n的最大的数x,使得f(x)最大,f(x)等于f(x-p^3)+1 (p是p^3小于等于n的最大的数)。


分析:打表后就能发现,对于给定的n,设p是p^3小于等于n的最大的数,那么最优解一定是在p^3到n或(p-1)^3到p^3之间的,直接DFS就能A,其实比赛时已经想到正解了,但

是看A的人数那么少于是就去玩守望先疯了,结果最后五分钟C也被人HACK了..

#include <queue>
#include <vector>
#include <cstdio>
#include <utility>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
long long n,ans;
typedef pair<int,long long> pii;
pii dfs(long long n)
{
	long long j = 1;
	for(;j*j*j <= n;j++);
	j--;
	if(j <= 1) return make_pair(n,1ll*n);
	pii now1 = dfs(n-j*j*j);
	pii now2 = dfs(j*j*j-(j-1)*(j-1)*(j-1)-1);
	if(now1.first >= now2.first) return make_pair(now1.first+1,now1.second+j*j*j);
	else return make_pair(now2.first+1,now2.second+(j-1)*(j-1)*(j-1));
}
int main()
{
	cin>>n;
	pii ans = dfs(n);
	cout<<ans.first<<" "<<ans.second<<endl;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值