【CodeForces】[546A]Soldier and Bananas

Problem Description

Loading...

Problem Analysis

Just compute it directly
There are no twists

Note that int is enough to store the data
When no borrowing is needed (n>res)
Output 0

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#include<stdio.h>
int main() {
	int k,n,w;
	while(scanf("%d %d %d",&k,&n,&w)!=EOF) {
		int res=0;
		for(int i=1; i<=w; i++)
			res+=i*k;
		if(n>res)
			printf("0\n");
		else
			printf("%d\n",res-n);
	}
	return 0;
}

Problem link:【CodeForces】[546A]Soldier and Bananas

This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...