Codeforces Round #323 (Div. 2) d.once Again ...

Source: Internet
Author: User

D. Once Again ...

You is given an array of positive integers a1, a2, ..., an x t of length n x T. We know that for any i > n It was true that ai = a i - n. Find the length of the longest non-decreasing sequence of the given array.

Input

The first line contains the space-separated integers: n, T (1≤ n ≤100, 1≤ t ≤10^ 7). The second line contains n space-separated integers a1, a2, ..., C16>an (1≤ ai ≤300).

Output

Print a single number-the length of a sought sequence.

Examplesinput
4 3
3 1 4 2
Output
5
Note

The array given in the sample looks like That:3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in Bol D form the largest non-decreasing subsequence.

Test instructions is to give a sequence and K value, this sequence can cycle k times, the longest non-descending subsequence, the value of K is very large, so nlogn also to fry. Think about it, even if all the numbers in the original array are in this sub-sequence, there are only 100, and the rest is sure to be able to insert the numbers at will, then the number is obviously the more the better. Then you can repeat the original array a lot (min (n, k)), and find its longest non-descending subsequence, and the number of occurrences of the most number in the remaining repeating sequence is the answer. (In fact, I played more than 10 minutes to think of, unfortunately found before actually put Nlogn lis write down, I copied the former Orz)

#include <iostream>#include<stdio.h>#include<queue>#include<map>#include<algorithm>using namespacestd;Const intMAXN = 1e4 +Ten;inttt[ the];intNUM[MAXN];intDp[maxn];map<int,int>MP;intMain () {intN, K;  while(~SCANF ("%d%d", &n, &k)) {intMaxnum =0, maxcnt =0;  for(inti =1; I <= N; i++) {scanf ("%d", &Tt[i]); Mp[tt[i]]++; if(Mp[tt[i]) >maxcnt) {Maxnum=Tt[i]; Maxcnt=Mp[tt[i]]; }        }        intCNT =0;  for(inti =1; I <= min (n, k); i++) {             for(intj =1; J <= N; J + +) {num[++CNT] =Tt[j]; }        }        intval =0; //printf ("%d\n", CNT);         for(inti =1; I <= CNT; i++) {            intPOS = Upper_bound (DP, DP + val, num[i])-DP; if(pos = = val) dp[val++] =Num[i]; ElseDp[pos] =Num[i]; }        if(k > N) val = val + (k-n) *maxcnt; //cout << last << "" << maxcnt << Endl;printf"%d\n", Val); }}

Codeforces Round #323 (Div. 2) d.once Again ...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.