ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1510. Order

Help! TLE19. What's wrong?
Posted by Maxim Afripov 3 Nov 2021 23:29
using System;
using System.Collections.Generic;
namespace Order {
    class Banknotes {
        public long value = 0;
        public int count = 0;
        public Banknotes(long value) {
            this.value = value;
        }
    }

    class Program {
        public static Banknotes FindMaxValue (List<Banknotes> list) {
            int _maxValue = list[0].count;
            Banknotes _maxBanknote = list[0];
            for (int index = 1; index < list.Count; index++) {
                if (list[index].count > _maxValue) {
                    _maxBanknote = list[index];
                    _maxValue = list[index].count;
                }
            }

            return _maxBanknote;
        }

        public static void Main (string[] args) {
            List<Banknotes> banknotes = new List<Banknotes>();
            int length = Convert.ToInt32(Console.ReadLine());
            if (length == 0) return;

            banknotes.Add(new Banknotes(Convert.ToInt64(Console.ReadLine())));
            banknotes[0].count = 1;
            for (int iterable = 1; iterable < length; iterable++) {
                long number = Convert.ToInt64(Console.ReadLine());
                for (int jterable = 0; jterable < banknotes.Count; jterable++) {
                    // Console.WriteLine($"{number} is {numbers[jterable].value}?");
                    if (number == banknotes[jterable].value) {
                        banknotes[jterable].count++;
                        // Console.WriteLine("yes");
                        break;
                    } else if (jterable + 1 == banknotes.Count) {
                      // Console.WriteLine("no");
                        banknotes.Add(new Banknotes(number));
                    }
                }
            }

            Console.WriteLine(FindMaxValue(banknotes).value);
        }
    }
}