304 North Cardinal St.
Dorchester Center, MA 02124

# The Theatre Problem CodeChef Solution

## The Theatre Problem CodeChef Solution in C++14

``````#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <limits.h>
#include <math.h>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iomanip>
// used for setprecision();
#include <string.h>
// used for memset();
#include <boost/multiprecision/cpp_int.hpp>
#define pll pair<long long, long long>
using namespace std;

#define ll long long
#define mod 1000000007
#define pll pair<long long, long long>
#define endl "\n"
#define LLMAX LONG_LONG_MAX
#define LLMIN LONG_LONG_MIN

void get_perms(int index, int length, vector<int> &original, vector<vector<int>> &perms) {
if (index == length) {
perms.push_back(original);
return;
}

for (ll i = index; i < length; i++) {
swap(original[index], original[i]);
get_perms(index + 1, length, original, perms);
swap(original[index], original[i]);
}
}

ll get_value(vector<int> &perms, vector<vector<ll>> &mat) {
vector<int> audience_count;
vector<int> ticket_cost = {25, 50, 75, 100};
for (ll i = 0; i < 4; i++)
audience_count.push_back(mat[perms[i]][i]);
sort (audience_count.begin(), audience_count.end());
ll profit = 0;
for (ll i = 3; i >= 0; i--) {
if (audience_count[i] == 0)
profit -= 100;
else
profit += audience_count[i] * ticket_cost[i];
}
return profit;
}

int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);

ll t = 0;
cin >> t;
vector<int> original = {0, 1, 2, 3};
vector<vector<int>> perms;
get_perms(0, 4, original, perms);
ll total = 0;
while (t--) {
ll n = 0;
cin >> n;
vector<vector<ll>> mat(4, vector<ll> (4, 0));
ll result = INT_MIN;
for (ll i = 0; i < n; i++) {
char movie = 'a';
int timeslot = 0;
cin >> movie >> timeslot;
int row = movie - 'A';
int col = (timeslot / 3) - 1;
mat[row][col] += 1;
}
for (ll i = 0; i < 24; i++) {
result = max(result, get_value(perms[i], mat));
// for (ll j = 0; j < 4; j++)
//     cout << perms[i][j] << " ";
// cout << get_value(perms[i], mat);
// cout << endl;
}
cout << result << endl;
total += result;
}
cout << total << endl;
return 0;
}

``````

## The Theatre Problem CodeChef Solution in PYTH 3

``````# cook your dish here
totals = []
for _ in range(int(input())):
N = int(input())
dp = [[0]*4 for i in range(4)]
converter = {
"A": 0,
"B": 1,
"C": 2,
"D": 3,
"12": 0,
"3": 1,
"6": 2,
"9": 3
}
def smartsum(arr):
z = sorted(arr, reverse=True)
m = [25, 50, 75, 100]
for i in range(len(z)):
if z[i] == 0:
z[i] = -100
else:
z[i] *= m.pop()
return(sum(z))
def helper(dp, list_ = [], sum_ = 0, depth = 0, vals = []):
maxx = None
if depth == 4:
return vals
for i in range(4):
if i not in list_:
new_sum = sum_ + dp[i][depth]
x = helper(dp, list_ + [i], new_sum, depth + 1, vals + [dp[i][depth]])
if maxx == None or smartsum(x) > smartsum(maxx):
maxx = x
return maxx
for i in range(N):
A, B = list(input().split())
dp[converter[A]][converter[B]] += 1
z = helper(dp)
z.sort(reverse = True)
m = [25, 50, 75, 100]
for i in range(len(z)):
if z[i] == 0:
z[i] = -100
else:
z[i] *= m.pop()
totals.append(sum(z))
print(sum(z))
print(sum(totals))``````

## The Theatre Problem CodeChef Solution in C

``````#include <stdio.h>
#include <stdlib.h>

int compare(const void *a, const void *b);

int main()
{
int Testcases;
scanf("%d", &Testcases);
long long total = 0;
while(Testcases--)
{
int N, i, t;

scanf("%d", &N);

char m;
int A[5] = {0}, B[5] = {0}, C[5] = {0}, D[5] = {0};

for(i = 1; i <= N; i++)
{
scanf("\n%c %d", &m, &t);
if(m == 'A')
{
if(t == 12)
{
A[1]++;
}
else if(t == 3)
{
A[2]++;
}
else if(t == 6)
{
A[3]++;
}
else
{
A[4]++;
}
}
else if(m == 'D')
{
if(t == 12)
{
D[1]++;
}
else if(t == 3)
{
D[2]++;
}
else if(t == 6)
{
D[3]++;
}
else
{
D[4]++;
}
}
else if(m == 'B')
{
if(t == 12)
{
B[1]++;
}
else if(t == 3)
{
B[2]++;
}
else if(t == 6)
{
B[3]++;
}
else
{
B[4]++;
}
}
else if(m == 'C')
{
if(t == 12)
{
C[1]++;
}
else if(t == 3)
{
C[2]++;
}
else if(t == 6)
{
C[3]++;
}
else
{
C[4]++;
}
}
}
int c, v, b, n;

long long int final, maxp = 0;
int prof = 100;
int sort[5];

for(c = 1; c <= 4; c++)
{

for(v = 1; v <= 4; v++)
{
if(v == c)
{
continue;
}
else
{
for(b = 1; b <= 4; b++)
{
if(b == c || b == v)
{
continue;
}
else
{
for(n = 1; n <= 4; n++)
{
if(n == c || n == v || n == b)
{
continue;
}
else
{
for(i = 0; i < 5; i++)
{
sort[i] = 0;
}
if(c == 1)
{
sort[1] = A[1];
}
else if(c == 2)
{
sort[1] = B[1];
}
else if(c == 3)
{
sort[1] = C[1];
}
else
{
sort[1] = D[1];
}

if(v == 1)
{
sort[2] = A[2];
}
else if(v == 2)
{
sort[2] = B[2];
}
else if(v == 3)
{
sort[2] = C[2];
}
else
{
sort[2] = D[2];
}

if(b == 1)
{
sort[3] = A[3];
}
else if(b == 2)
{
sort[3] = B[3];
}
else if(b == 3)
{
sort[3] = C[3];
}
else
{
sort[3] = D[3];
}

if(n == 1)
{
sort[4] = A[4];
}
else if(n == 2)
{
sort[4] = B[4];
}
else if(n == 3)
{
sort[4] = C[4];
}
else
{
sort[4] = D[4];
}

qsort(sort, 5, sizeof(int), compare);

i = 4;
while(i >= 1)
{
if(sort[i] == 0)
{
maxp -= 100;
}
else
{
maxp += (prof * sort[i]);
prof -= 25;
}
i--;
}
if(c == 1 && v == 2 && b == 3 && n == 4)
{
final = maxp;
}
else if(maxp > final)
{
final = maxp;
}
maxp = 0;
prof = 100;
}
}
}
}
}

}
}
printf("%lld\n", final);
total += final;
}
printf("%lld\n", total);
exit(0);
}

int compare(const void *a, const void *b)
{
return (*(int *)a - *(int *)b);
}``````

## The Theatre Problem CodeChef Solution in JAVA

``````import java.io.*;
import java.util.*;

class Chcbox {
InputStream is;
PrintWriter out;
String INPUT = "";
ArrayList<List<Integer>> main = new ArrayList<>();

void solve() throws Exception {
long maina = 0;
for (int T = ni(); T > 0; T--) {
int n = ni();
int[][] f = new int[4][4];
int[] p = new int[4];
int[] f2 = new int[4];
for (int i=0;i<n;i++){
char c=nc();
int x=ni();
++f[getMovieID(c)][getShowtimeID(x)];
}
// System.out.println(Arrays.deepToString(f));
int ans = Integer.MIN_VALUE;
for (int i=0;i<4;i++)
p[i] = i;

do {
for (int i=0;i<4;++i)
f2[i] = f[i][p[i]];
///    System.out.println(Arrays.toString(f2));
int ca=0;
Arrays.sort(f2);
for(int i=0;i<4;++i)
ca+=(i+1)*25*f2[i];
for (int i=0;i<4;++i)
if(f2[i] == 0)
ca-=100;
ans = Math.max(ca, ans);
} while (findNextPermutation(p));
out.println(ans);
maina += ans;
}
out.println(maina);
}

int getMovieID(char c){
return c-'A';
}

int getShowtimeID(int x){
return x/3-1;
}

public static boolean findNextPermutation(int[] data)
{
if(data.length <= 1)
return false;
int last = data.length-2;
while (last >= 0){
if(data[last] < data[last+1]){
break;
}
last--;
}
if(last<0)
return false;
int nextGreater = data.length-1;
for (int i=data.length-1;i>last;i--){
if(data[i] > data[last]) {
nextGreater = i;
break;
}
}
data = swap(data, nextGreater, last);
data = reverse(data, last+1, data.length-1);
return true;
}

public static int[] reverse(int[] data, int left, int right){
while (left<right){
int temp = data[left];
data[left++] = data[right];
data[right--] = temp;
}
return data;
}

public static int[] swap(int[] data, int left, int right)
{
int temp = data[left];
data[left] = data[right];
data[right] = temp;

return data;
}

void run() throws Exception
{
is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
out = new PrintWriter(System.out);

long s = System.currentTimeMillis();
solve();
out.flush();
if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");
}

public static void main(String[] args) throws Exception { new Chcbox().run(); }

private byte[] inbuf = new byte[1024];
public int lenbuf = 0, ptrbuf = 0;

{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}

private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

private double nd() { return Double.parseDouble(ns()); }
private char nc() { return (char)skip(); }

private String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
}
return sb.toString();
}

private char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
}
return n == p ? buf : Arrays.copyOf(buf, p);
}

private char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}

private int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}

private int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
}

while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
}
}

private long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
}

while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
}
}

private void tr(Object... o) { if(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}``````

## The Theatre Problem CodeChef Solution in PYPY 3

``````
from itertools import permutations
tots=0
test=int(input())
while(test!=0):
n=int(input())
tw=[0,0,0,0]
th=[0,0,0,0]
si=[0,0,0,0]
ni=[0,0,0,0]
s=[0,1,2,3]
for i in range(n):
m,t = map(str,input().split())
t=int(t)
if m=="A":
ind=0
elif m=="B":
ind=1
elif m=="C":
ind=2
elif m=="D":
ind=3
if t==12:
tw[ind]+=1
elif t==3:
th[ind]+=1
elif t==6:
si[ind]+=1
else:
ni[ind]+=1
co = list(permutations(s,4))
total=float("-inf")
for value in co:
p=[tw[value[0]],th[value[1]],si[value[2]],ni[value[3]]]
p.sort(reverse=True)
tot=0
for i in p:
if i==0:
tot-=100
tot+=p[0]*100
tot+=p[1]*75
tot+=p[2]*50
tot+=p[3]*25
if tot>total:
total=tot
print(total)
tots+=total
test-=1
print(tots)``````

## The Theatre Problem CodeChef Solution in PYTH

``````C = [25,50,75,100]
Z = [[0, 1, 2, 3], [0, 1, 3, 2], [0, 2, 1, 3], [0, 2, 3, 1], [0, 3, 1, 2], [0, 3, 2, 1], [1, 0, 2, 3], [1, 0, 3, 2], [1, 2, 0, 3], [1, 2, 3, 0], [1, 3, 0, 2], [1, 3, 2, 0], [2, 0, 1, 3], [2, 0, 3, 1], [2, 1, 0, 3], [2, 1, 3, 0], [2, 3, 0, 1], [2, 3, 1, 0], [3, 0, 1, 2], [3, 0, 2, 1], [3, 1, 0, 2], [3, 1, 2, 0], [3, 2, 0, 1], [3, 2, 1, 0]]
t = int(raw_input())
gtot = 0
for i in range(t):
G = [[0 for x in range(4)] for y in range(4)]
N = int(raw_input())
for k in range(N):
st = raw_input().split()
m = ord(st[0])-65
s = int(st[1])/3 -1
G[m][s] += 1
# endfor k
mx = -400
for z in Z:
L = []
for p in range(4):
q = z[p]
L.append(G[p][q])
# endfor p
L.sort()
tot = 0
for p in range(4):
n = L[p]
if n == 0:
tot -= 100
else:
tot += n*C[p]
# endif
# endfor p
if tot > mx:
mx = tot
# endif
# endfor z
print mx
gtot += mx
# endfor i
print gtot
``````

## The Theatre Problem CodeChef Solution in C#

``````using System;
using System.Collections.Generic;
using System.Linq;

namespace codechef
{
class Program
{

static float finalAnswer = 0;

static void Main(string[] args)
{
int T = int.Parse(Console.ReadLine());
for (int i = 0; i < T; i++)
{

int[,] ans = new int[4, 4];

int N = int.Parse(Console.ReadLine());
for (int x = 0; x < N; x++)
{
string[] s = Console.ReadLine().Split(' ');
int val = int.Parse(s[1]) / 3 - 1;

switch (s[0])
{
case "A":
ans[0, val] += 1;
break;
case "B":
ans[1, val] += 1;
break;
case "C":
ans[2, val] += 1;
break;
case "D":
ans[3, val] += 1;
break;

//long[] B = Array.ConvertAll(Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries), (element) => long.Parse(element));
}

}

}

}
static float Movie(int[,] ans)
{
int result=int.MinValue;
bool[] req = new bool[] { false };
int n = 4;

for(int C = 0; C < n; C++)
{
for (int x = 0; x < n; x++)
{
if (C == x) { continue; }

for (int a = 0; a < n; a++)
{
if (a == C || a == x) { continue; }

for (int b = 0; b < n; b++)
{
if (b == C || b == x || b == a) { continue; }

int[] found = { ans[0,C] , ans[1,x] , ans[2,a],
ans[3,b]};

Array.Sort(found);
int loss = 0,time=0;

for(int m =3; m >= 0; m--)
{
if (found[m] == 0)
{
loss -= 100;
}
else
{
time = 3 - m;
loss += found[m] * (100 - 25 * time);
}
}

result = Math.Max(result, loss);
}
}
}
}
Console.WriteLine(result);
return result;
}
}
}``````

## The Theatre Problem CodeChef Solution in NODEJS

``````process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', (inputStdin) => {
inputString += inputStdin;
});

process.stdin.on('end', (_) => {
inputString = inputString.trim().split('\n').map((string) => {
return string.trim();
});

main();
});

return inputString[currentLine++];
}

let tf = Array(4).fill(false).map((x) => Array(4).fill(false));
let ntf = Array(4).fill(false).map((x) => Array(4).fill(false));
let sum = Number.NEGATIVE_INFINITY;

function main() {
// let a = [ [ 1, 0, 1, 0 ], [ 0, 0, 2, 3 ], [ 0, 2, 0, 1 ], [ 2, 0, 0, 0 ] ];
let t = readline();
let finans = 0;
while (t--) {
tf = Array(4).fill(false).map((x) => Array(4).fill(false));
ntf = Array(4).fill(false).map((x) => Array(4).fill(false));
sum = Number.NEGATIVE_INFINITY;
let a = Array(4).fill(0).map((x) => Array(4).fill(0));
//let a = [ [ 0, 2, 0, 2 ], [ 2, 0, 0, 0 ], [ 0, 0, 2, 2 ], [ 0, 0, 2, 0 ] ];
let n = readline();
while (n--) {
let [ c, time ] = readline().split(' ');
c = c.charCodeAt(0) - 65;
time = time / 3 - 1;
a[c][time]++;
}
Counter(0, a);
console.log(sum);
finans += sum;
}
console.log(finans);
}

sumcalculator = (a) => {
let ans = [];
for (let i = 0; i < 4; i++) {
for (let j = 0; j < 4; j++) {
if (tf[i][j]) ans.push(a[i][j]);
}
}
ans.sort((a, b) => b - a);
let s = 0;
if (ans.length > 0)
for (let i = 0; i < 4; i++) {
if (ans[i] == 0) s -= 100;
else s += ans[i] * (100 - 25 * i);
}
else s = -400;
if (s > sum) {
sum = s;
ntf = tf.map((x) => x.slice());
}
};

Counter = (col, a) => {
if (col === 4) {
sumcalculator(a);
} else {
for (let i = 0; i < 4; i++) {
if (isSafe(i, col)) {
tf[i][col] = true;
Counter(col + 1, a);
}
tf[i][col] = false;
}
}
};

isSafe = (x, y) => {
for (let i = y; i >= 0; i--) {
if (tf[x][i]) return false;
}
return true;
};``````

## The Theatre Problem CodeChef Solution in GO

``````package main

import (
"bufio"
"fmt"
"io"
"os"
"sort"
"strconv"
)

var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
// max token size
scanner.Split(bufio.ScanWords)
scanner.Buffer([]byte{}, max_token_size)
}

func die(v ...interface{}) {
fmt.Fprintln(os.Stderr, v...)
os.Exit(1)
}

func NextInt() int {
bytes := NextBytes()
i, err := Atoi(bytes)
if err != nil {
die(err)
}
return i
}

func NextBytes() []byte {
if !scanner.Scan() {
die(scanner.Err())
}
return scanner.Bytes()
}

func Atoi(b []byte) (int, error) {
neg := false
if b[0] == '+' {
b = b[1:]
} else if b[0] == '-' {
neg = true
b = b[1:]
}
n := 0
for _, v := range b {
if v < '0' || v > '9' {
return 0, strconv.ErrSyntax
}
n = n*10 + int(v-'0')
}
if neg {
return -n, nil
}
return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
if size <= len(a) {
return a
} else {
return append(a, make([]byte, size-len(a))...)
}
}

func ExtendIntArray(a []int, size int) []int {
if size <= len(a) {
return a
} else {
return append(a, make([]int, size-len(a))...)
}
}

// Perm calls f with each permutation of a.
func Perm(a []int, f func([]int)) {
perm(a, f, 0)
}

// Permute the values at index i to len(a)-1.
func perm(a []int, f func([]int), i int) {
if i > len(a) {
f(a)
return
}
perm(a, f, i+1)
for j := i + 1; j < len(a); j++ {
a[i], a[j] = a[j], a[i]
perm(a, f, i+1)
a[i], a[j] = a[j], a[i]
}
}

var prices = [4]int{25, 50, 75, 100}
var counts = []int{0, 0, 0, 0}

func solve(n int, requests [][2]int) int {
var d [4][4]int
for i := 0; i < n; i++ {
d[requests[i][1]][requests[i][0]]++
}
res := -1000000000

Perm([]int{0, 1, 2, 3}, func(a []int) {
for showtime, movie := range a {
counts[showtime] = d[showtime][movie]
}
sort.Ints(counts)
sum := 0
for i := 0; i < 4; i++ {
if counts[i] == 0 {
sum -= 100
} else {
sum += counts[i] * prices[i]
}
}
if sum > res {
res = sum
}
})

return res
}

func main() {
f := os.Stdin
out := os.Stdout
// f, err := os.Open("a.in")
// if err != nil {
// 	die(err)
// }
// out, err := os.Create("a.out")
// if err != nil {
// 	die(err)
// }
// defer out.Close()
Init(f, 22)

T := NextInt()
requests := make([][2]int, 0)
var n int
var chByte []byte
timeMap := map[int]int{
3:  0,
6:  1,
9:  2,
12: 3,
}
totalRes := 0
for t := 0; t < T; t++ {
n = NextInt()
if n > len(requests) {
requests = append(requests, make([][2]int, n-len(requests))...)
}
for i := 0; i < n; i++ {
chByte = NextBytes()
requests[i][0] = int(chByte[0] - 'A')
requests[i][1] = timeMap[NextInt()]
}
res := solve(n, requests)
totalRes += res
fmt.Fprintln(out, res)
}
fmt.Fprintln(out, totalRes)
}``````
##### The Theatre Problem CodeChef Solution Review:

In our experience, we suggest you solve this The Theatre Problem CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the The Theatre Problem CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this The Theatre Problem CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!