Submission #1690590


Source Code Expand

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
//using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N, T;
    void solve()
    {
        N = cin.nextint;
        T = cin.nextint;
        var A = cin.scanint;


        int min = A[0];
        int max = A[0];

        int mincnt = 1;
        int maxcnt = 1;

        int value = 0;
        int valuecnt = 1;

        for (int i = 1; i < N; i++)
        {
            if (min == A[i])
            {
                mincnt++;
                continue;
            }
            if (A[i] < min)
            {
                min = A[i];
                mincnt = 1;
                continue;
            }

            if (value < A[i] - min)
            {
                value = A[i] - min;
                maxcnt = mincnt;
                valuecnt = 1;
            }
            else if (value == A[i] - min)
            {
                maxcnt++;
                valuecnt++;
            }
            //WriteLine(value + " " + valuecnt + " " + maxcnt);
        }

        //WriteLine(value + " " + valuecnt + " " + maxcnt);
        WriteLine(Math.Min(valuecnt, maxcnt));


    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Submission Info

Submission Time
Task D - An Invisible Hand
User claw88
Language C# (Mono 4.6.2.0)
Score 400
Code Size 2774 Byte
Status AC
Exec Time 69 ms
Memory 20576 KB

Judge Result

Set Name sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 15
Set Name Test Cases
sample sample_01.txt, sample_02.txt, sample_03.txt
All large_01.txt, large_02.txt, random_01.txt, random_02.txt, sample_01.txt, sample_02.txt, sample_03.txt, small_01.txt, small_02.txt, spec_01.txt, spec_02.txt, spec_03.txt, spec_04.txt, spec_05.txt, spec_06.txt
Case Name Status Exec Time Memory
large_01.txt AC 66 ms 16480 KB
large_02.txt AC 55 ms 14816 KB
random_01.txt AC 68 ms 18528 KB
random_02.txt AC 68 ms 18400 KB
sample_01.txt AC 23 ms 9044 KB
sample_02.txt AC 23 ms 11220 KB
sample_03.txt AC 23 ms 9172 KB
small_01.txt AC 22 ms 9044 KB
small_02.txt AC 23 ms 9044 KB
spec_01.txt AC 67 ms 18528 KB
spec_02.txt AC 67 ms 18528 KB
spec_03.txt AC 69 ms 18528 KB
spec_04.txt AC 68 ms 16480 KB
spec_05.txt AC 67 ms 18528 KB
spec_06.txt AC 69 ms 20576 KB