Soldier and Bananas
Explicación
Podemos hallar el costo total de bananas calculando la suma de los números de y multiplicándola por el precio de la primera banana, .
Ahora solo hay que comparar cuánto dinero hace falta para comprar las bananas.
Implementación
Complejidad temporal:
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));
}
}