Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be mZ http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vcmUgdGhhbjxlbT54PC9lbT48ZW0+aTwvZW0+IGJveGVzCiBvbiB0aGUgdG9wIG9mIDxlbT5pPC9lbT4tdGggYm94LiBXaGF0IGlzIHRoZSBtaW5pbWFsIG51bWJlciBvZiBwaWxlcyBzaGUgbmVlZHMgdG8gY29uc3RydWN0PzwvcD4KCgoKSW5wdXQKPHA+ClRoZSBmaXJzdCBsaW5lIGNvbnRhaW5zIGFuIGludGVnZXIgPGVtPm48L2VtPiAoMT+h3D88ZW0+bjwvZW0+P6HcPzEwMCkuCiBUaGUgbmV4dCBsaW5lIGNvbnRhaW5zIDxlbT5uPC9lbT4gaW50ZWdlcnMgPGVtPng8L2VtPjEsPzxlbT54PC9lbT4yLD8uLi4sPzxlbT54PC9lbT48ZW0+bjwvZW0+ICgwP6HcPzxlbT54PC9lbT48ZW0+aTwvZW0+P6HcPzEwMCkuPC9wPgoKCgpPdXRwdXQKPHA+Ck91dHB1dCBhIHNpbmdsZSBpbnRlZ2VyIKGqIHRoZSBtaW5pbWFsIHBvc3NpYmxlIG51bWJlciBvZiBwaWxlcy48L3A+CgoKClNhbXBsZSB0ZXN0KHMpCgoKCmlucHV0CjxwcmUgY2xhc3M9"brush:java;">3 0 0 10
output2input
5 0 1 2 3 4output
1input
4 0 0 0 0output
4input
9 0 1 0 2 0 1 1 2 10output
3Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
#include
#include
#include
#include
using namespace std; int st[1000],n,ans=0; int vis[1000]; int main() { scanf("%d",&n); for(int i=0;i
=strength) { vis[j]=ans; strength++; } } } } printf("%d\n",ans); return 0; }