Problem:


  MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});

プログラミングコンテスト

今年も白虎大学でプログラミングコンテストが開催されることになりました。コンテストではいくつかの問題が出題され、それぞれ難易度に応じた得点が割り当てられています。

実行委員会は、解いた問題の数とそれらの得点の両方を考慮し、次のルールに基づいて各チームのスコアを計算することにしました。

「あるチームが正解した問題のうち、得点が A 以上であるものが A 問以上あることを満たすような最大の A を、そのチームのスコアとする」

あるチームが正解した問題の数と、それらの問題の得点から、チームのスコアを計算するプログラムを作成せよ。

Input

入力は以下の形式で与えられる。

N
p1 p2 ... pN

１行目にチームが正解した問題の数 N (1 ≤ N ≤ 100) が与えられる。２行目に正解した各問題の得点 pi(1 ≤ pi ≤ 100) が与えられる。

Output

チームのスコアを１行に出力する。

Sample Input 1

7
5 4 3 10 2 4 1

Sample Output 1

4

得点が 4 以上の問題を 4 問以上正解しているので、スコアは 4 となる。

Sample Input 2

3
1 1 100

Sample Output 2

1

得点が 1 以上の問題を 1 問以上正解しているので、スコアは 1 となる。

Sample Input 3

4
11 15 58 1

Sample Output 3

3

得点が 3 以上の問題を 3 問以上正解しているので、スコアは 3 となる。



Sample input:
7
5 4 3 10 2 4 1


Sample output:
4

Submission status: Wrong Answer

Solution code:
n = int(input())
p = list(map(int, input().split()))

def count(l, n):
    ans = 0
    for i in l:
        if i >= n:
            ans += 1
    return ans

for i in sorted(p, reverse=1):
    if count(p, i) >= i:
        print(i)
        break

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    p = list(map(int, input().split()))
    p.sort()
    pp = list(set(p))

    cnt = 0
    for i in range(len(pp)):
        cnt += 1
        scnt = 0
        for j in range(len(p)):
            if pp[i] <= p[j]:
                scnt += 1
        if cnt == scnt:
            break
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    p = list(map(int, input().split()))
    p.sort()
    pp = list(set(p))

    cnt = 0
    for i in range(len(pp)):
        cnt += 1
        scnt = 0
        for j in range(len(p)):
            if pp[i] <= p[j]:
                scnt += 1
        if cnt == scnt:
            break
    print(scnt)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
score = [0] * 101
for x in p:
    score[x] += 1

for i in range(101):
    if sum(score[i:]) < i:
        break
print(i-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
score = [0] * 101
for x in p:
    score[x] += 1

for i in range(1, 101):
    if sum(score[i:]) < i:
        break
print(i-1)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = list(map(int, input().split()))
score = [0] * 101
for x in p:
    score[x] += 1
print(max(i * sum(score[i:]) >= i) for i in range(101))

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))

def count(l, n):
    ans = 0
    for i in l:
        if i >= n:
            ans += 1
    return ans

for i in reversed(range(max(p)+1)):
    if count(p, i) >= i:
        print(i)
        break

Submission status: Accepted

Solution code:

N = int(input())
p = [int(i) for i in input().split()]
p.sort()
p.reverse()
ans = 0

for i in range(len(p)):
    if p[i] >= i + 1:
        ans = i + 1
    else:
        break
        
print(ans)

Submission status: Accepted

Solution code:
input();Q=[0]*101
for p in map(int,input().split()):Q[p]+=1
print(max(i for i in range(101)if sum(Q[i:])>=i))

Submission status: Accepted

Solution code:
def check(p,A):
    cnt = 0
    for a in p:
        if a >= A:
            cnt+=1
    return cnt >= A

def main():
    N=int(input())
    p=list(map(int,input().split()))
    for A in range(100,-1,-1):
        if check(p,A):
            print(A)
            return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    p = list(map(int, input().split()))
    ans = []

    sc = 1 #score count
    for _ in range(N):
        cnt = 0
        for i in range(len(p)):
            if p[i] >= sc:
                cnt += 1
        if cnt >= sc:
            ans.append(sc)
        sc += 1

    ans.sort(reverse = True)
    print(ans[0])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from itertools import takewhile as T

N = int(input())
p = list(map(int, input().split()))
score = [0] * 101
for x in p:
    score[x] += 1

print(len(list(T(lambda i: sum(score[i:]) >= i, range(1, 101)))))

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, input().split()))
score = [0] * 101
for x in p:
    score[x] += 1
    
i = 1
while sum(score[i:]) >= i:
    i += 1
print(i-1)

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, input().split()))
score = [0] * 101
for x in p:
    score[x] += 1

i = 1
while True:
    if sum(score[i:]) < i:
        break
    i += 1
print(i-1)

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, input().split()))
score = [0] * 101
for x in p:
    score[x] += 1
print(max(i * (sum(score[i:]) >= i) for i in range(101)))

Submission status: Accepted

Solution code:
n = int(input())
p = sorted(list(map(int, input().split())), reverse = True)
for i in range(n)[::-1]:
    if p[i] >= i + 1:
        print(i + 1)
        break

Submission status: Accepted

Solution code:
n = int(input())
plst = sorted(list(map(int, input().split())))
for i in range(n, 0, -1):
  if len([p for p in plst if p >= i]) >= i:
    print(i)
    break

Submission status: Accepted

Solution code:
# coding=utf-8

if __name__ == '__main__':
    N = int(input())
    score_list = list(map(int, input().split()))
    score_list.sort(reverse=True)

    ctr = 1
    for element in score_list:
        if ctr > element:
            print(ctr-1)
            break
        ctr += 1
    else:
        print(ctr-1)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))

for n in range(N, 0, -1):
	tmp = len([i for i in A if i>=n])
	if n<=tmp:
		print(n)
		break

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))
p.sort(reverse = True)
end=0
for i in range(n) :
    if p[i] < i+1 :
        print(i)
        end=1
        break
if end == 0 :
    print(i+1)

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1,n+1):
    if i<=len(list(filter(lambda x: x>=i, p))):
        ans = i

print(ans)

Submission status: Accepted

Solution code:
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


SIZE = 105
table = [0]*SIZE

N = int(input())
input_array = list(map(int,input().split()))

maximum = 0

for i in range(N):
    table[0] -= 1
    table[input_array[i]] += 1
    maximum = max(maximum,input_array[i])

for i in range(maximum-1,-1,-1):
    table[i] += table[i+1]

ans = 0

for i in range(1,maximum+1):
    if i <= table[i]:
        ans = i

print("%d"%(ans))

Submission status: Accepted

Solution code:
n = int(input())
p = sorted(list(map(int,input().split())), reverse=True)
max = 0
for i in range(n):
    if(p[i] > i):
        max = i+1
print(max)

Submission status: Accepted

Solution code:
N=int(input())
P=list(map(int,input().split()))
P.sort(reverse=True)
result=0

for i in range(N):
    if P[i]>=i+1:
        result=i+1
print(result)

Submission status: Accepted

Solution code:
n = int(input())
bunpu = [0]*101
for i in list(map(int, input().split())): bunpu[i]+=1
sm = 0
for i in range(100, -1, -1):
    sm += bunpu[i]
    if i<=sm:
        print(i)
        break
else: print(0)

Submission status: Accepted

Solution code:
N = int(input())
p = list(map(int, input().split()))

for i in range(100, 0, -1):
    if i <= len([x for x in p if i <= x]):
        print(i)
        break

Submission status: Accepted

Solution code:
n=int(input())
point=list(map(int,input().split()))
for i in range(n+1)[::-1]:
    count=0
    for j in point:
        if j>=i:count+=1
    if count>=i:
        print(i)
        break

Submission status: Accepted

Solution code:
n = int(input())
p = list(map(int, input().split()))

for i in range(100, 0, -1):
    if len([x for x in p if x >= i]) >= i:
        print(i)
        break

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    p = list(map(int, input().split()))
    p.sort()
    pp = list(set(p))

    cnt = 0
    for i in range(len(pp)):
        cnt += 1
        scnt = 0
        for j in range(len(p)):
            if pp[i] <= pp[j]:
                scnt += 1
        if cnt == scnt:
            break
    print(cnt)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
p = list(map(int, input().split()))
score = [0] * 101
for x in p:
    score[x] += 1

while True:
    if sum(score[i:]) < i:
        break
    i += 1
print(i-1)