Algorithm
Problem Name: beecrowd | 2540
Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2540
Leader's Impeachment
By Ricardo Oliveira, UFPR Brazil
Timelimit: 1
Analógimôn Go! is a very popular game. The players of this game are divided in three teams: Team Valor, Team Instinct and Team Mystic, which are led by their leaders, Kandera, Esparky and Blanque, respectively. Of course, you belong to one of these teams!
The leader of your team is being accused of cheating by incorrectly managing the candies the team receives from the Professor. This fact created a big controversy among the players in the team: some players state that the leader really cheated, must suffer an impeachment and must leave his position as a leader, while other players state that he did not cheat, that the accusation is false and he must keep leading the team.
To solve this situation, a poll will be held with all N players in your team. Each player must vote if the impeachment must or must not occur. If the number of votes for the impeachment is greater than or equal to 2/3 (two thirds) of the total number of players in the team, the leader will lost his position. Otherwise, the accusation will be filed and he will keep leading the team.
Given the votes of all players, determine the result of the poll.
Input
The input contains several test cases. The first line of each test case contains the integer N (1 ≤ N ≤ 105), the number of players in your team. Next line contains N integers v1, ..., vN (vi = 0 or 1), indicating the votes of each player. The value 1 indicates a vote for the impeachment, while value 0 indicates a vote against it.
The input ends with end-of-file (EOF).
Output
For each test case, print a single line containing the word impeachment if the leader must leave his position, or acusacao arquivada otherwise.
Input Sample | Output Sample |
6 |
impeachment |
Code Examples
#1 Code Example with C Programming
Code -
C Programming
#include <stdio.h>
#include <math.h>
int main(void)
{
int i, j, a, b, n, x;
double y;
while (scanf("%i", &n) != EOF)
{
x = 0;
for (i = 0; i < n; ++i)
{
scanf("%i", &a);
if (a == 1)
++x;
}
y = (2*n)/3.0;
b = ceil(y);
if (x >= b)
printf("impeachment\n");
else
printf("acusacao arquivada\n");
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#2 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
int m;
while(cin >> n)
{
int _1 = 0;
for(int i = 0; i < n; i++)
{
cin >> m;
if(m)
_1++;
}
float M = ceil(n*.666);
int x = (int) M;
if(_1 >= x)
cout << "impeachment\n";
else cout << "acusacao arquivada\n";
}
return 0;
}
Copy The Code &
Try With Live Editor
Input
Output
#3 Code Example with Javascript Programming
Code -
Javascript Programming
const { readFileSync } = require("node:fs")
const input = readFileSync("/dev/stdin", "utf8").split("\n")
function main() {
const output = []
for (let i = 0; i < input.length; i += 2) {
if (input[i] == "") break // EOFile Condition
const votesQuantity = Number.parseInt(input[i], 10)
const positiveVotesQuantity = input[i + 1].split(" ", votesQuantity).filter(v => v == "1").length
output.push(votesQuantity * 2 > 3 * positiveVotesQuantity ? "acusacao arquivada" : "impeachment")
}
console.log(output.join("\n"))
}
main()
Copy The Code &
Try With Live Editor
Input
Output
#4 Code Example with Python Programming
Code -
Python Programming
while True:
try:
n = int(input())
v = input().split()
v = v.count('1')
if v/n >= 2/3:
print('impeachment')
else:
print('acusacao arquivada')
except EOFError:
break
Copy The Code &
Try With Live Editor
Input
Output
#5 Code Example with Java Programming
Code -
Java Programming
import java.util.Locale;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
sc.useLocale(Locale.ENGLISH);
Locale.setDefault(new Locale("en", "US"));
while(sc.hasNext()) {
int total = sc.nextInt();
double contavotos=0;
for (int i=0 ; i < total ; i++)
if (sc.nextInt()==1)
contavotos++;
double doisterços = total*0.6666666666666667;
if(contavotos>=doisterços)
System.out.println("impeachment");
else
System.out.println("acusacao arquivada");
}
sc.close();
}
}
Copy The Code &
Try With Live Editor
Input
Output