my code

Ball Stacking

Snippet options

Download: Download snippet as bcpp.cpp.
Copy snippet: For this you need a free my code account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

#include <bits/stdc++.h>
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define mk make_pair
#define pb push_back 
#define fi first
#define se second
const int INF = 0x3f3f3f3f;

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
const int N=1010;
int vec[N][N], n;
ll mx[2][N];

int main(){
	while(cin>>n) {
		memset(mx,0,sizeof mx);
		for(int i=0;i<n;i++)
			for(int j=0;j<=i;j++)

		int prv=0, curr=1;
		ll ans=0;

		for(int i=0;i<n;i++) {
			ll s=0;
			for(int j=0;j<n-i;j++) {
			for(int j=n-i-1;j>=0;j--) {
				mx[curr][j]=max(mx[curr][j], mx[curr][j+1]);

        return 0;

Create a free my code account now.

my code is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.