Skip to content

Instantly share code, notes, and snippets.

@balamark
Created April 13, 2015 14:20
Show Gist options
  • Save balamark/fdda9bc3cbfc8357fad5 to your computer and use it in GitHub Desktop.
Save balamark/fdda9bc3cbfc8357fad5 to your computer and use it in GitHub Desktop.
clean way. approaching from two endpoints.
/*
* updown /\ up / down \
* / \ / \
* / \ / \
* v1 v2 v1 v2
*/
int ans=v1+v2;
t-=2;
REP(k,t){
if(v1<=v2){
v1+=d;
ans+=v1;
}
else{
v2+=d;
ans+=v2;
}
}
cout<<ans<<endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment