You are viewing a single comment's thread. Return to all comments →
My C solution :
int main() {
int i, n; scanf("%d", &n); int child[n], candy[n]; for(i=0; i<n; i++) scanf("%d", (child+i)), *(candy+i) = 1; for(i=1; i<n; i++) if(*(child+i) > *(child+i-1)) *(candy+i) = *(candy+i-1) + 1; for(i=n-2; i>=0; i--) if(*(child+i) > *(child+i+1) && *(candy+i) < *(candy+i+1) + 1) *(candy+i) = *(candy+i+1) + 1; long long total = 0; for(i=0; i<n; i++) total += *(candy+i); printf("%lld", total); return 0;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Candies
You are viewing a single comment's thread. Return to all comments →
My C solution :
int main() {
}