Algorithm
Problem Name: beecrowd | 2982
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2982
The Strike Stops or Continues?
By Roger Eliodoro Condras, UFSC-ARA Brazil
Timelimit: 1
In order to stop the general student strike, the government held a meeting with the UFSC. During the meeting, UFSC explained all the expenses needed to keep it running until the end of the year, and the Government reported amounts it could offer to cover these expenses. The meeting was not very organized, and several individual values were mentioned, so no one knows if the amounts offered are sufficient to cover all university expenses.
Given the list of values cited at the meeting, your task will be to sum the expenses and funds offered to inform UFSC students whether the strike should stop or not.
Input
The entry starts with an integer N (1
N 100,000) that indicates the number of values cited in the meeting. Each line has a T character and an integer C (1 C
100,000) separated by a blank space. T will be equal to 'V' if value C represents a government grant, or equal to 'G' if value C represents a university expense.
Output
Print out “The strike will stop.” If government figures are enough to cover all university spending by the end of the year, or print “NO CUT, FIGHT!” Otherwise. (In both cases the sentence must be printed without quotation marks).
Input Sample | Output Sample |
5 |
NAO VAI TER CORTE, VAI TER LUTA! |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
int main(int argc, char **argv)
{
char c;
int i, n, x;
long long ans = 0;
scanf("%d%*c", &n);
for (i = 0; i < n; ++i)
{
scanf("%c %d%*c", &c, &x);
if (c == 'G')
ans -= x;
else
ans += x;
}
if (ans >= 0)
puts("A greve vai parar.");
else
puts("NAO VAI TER CORTE, VAI TER LUTA!");
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("fs")
const [[numLines], ...lines] = readFileSync("/dev/stdin", "utf8")
.split("\n")
.map(line => line.split(" ", 2))
function main() {
const { G: expenses, V: resource } = lines
.slice(0, Number.parseInt(numLines, 10))
.map(([label, value]) => [label, Number.parseInt(value, 10)])
.reduce((pair, [label, value]) => (pair[label] += value, pair), { G: 0, V: 0 })
console.log(resource < expenses ? "NAO VAI TER CORTE, VAI TER LUTA!" : "A greve vai parar.")
}
main()
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.split('\n');
const number = parseInt(lines.shift());
let gastos = 0;
let verba = 0;
for(let i = 0; i < number; i++){
let [a, b] = lines.shift().trim().split(" ");
a == "G" ? gastos += parseInt(b) : verba += parseInt(b);
}
if(verba >= gastos){
console.log("A greve vai parar.");
}
else{
console.log("NAO VAI TER CORTE, VAI TER LUTA!");
}
Copy The Code &
Try With Live Editor
Input
Output