Skip to Content

Soldier and Bananas

Editorial oficial 

Explicación

Podemos hallar el costo total de ww bananas calculando la suma de los números de 1W1 - W y multiplicándola por el precio de la primera banana, kk.

Ahora solo hay que comparar cuánto dinero hace falta para comprar las bananas.

Implementación

Complejidad temporal: O(1)\mathcal{O}(1)

first, money, num = map(int, input().split()) cost = num * (num + 1) // 2 cost *= first print(max(0, cost - money))
#include <iostream> using namespace std; int main() { int first, num; long long money; cin >> first >> money >> num; int cost = num * (num + 1) / 2; cost *= first; cout << (max(0, cost - money)); }
import java.io.*; import java.util.*; public class SoldierBananas { public static void main(String[] args) { Scanner input = new Scanner(System.in); int first = input.nextInt(); long money = input.nextInt(); int num = input.nextInt(); long cost = num * (num + 1) / 2; cost *= first; System.out.println(Math.max(cost - money, 0)); } }