Điểm:
800 (p)
Thời gian:
1.0s
Bộ nhớ:
256M
Input:
bàn phím
Output:
màn hình
Cho một dãy gồm \(N\) số nguyên dương \(A_1, A_2,…, A_N\).(\(N ≤ 10^4, A_i ≤ 10^9\)) và số \(K\) (\(K ≤ N\)). Hãy in ra số nhỏ thứ \(K\) trong dãy.
Input
- Dòng đầu chứa số \(N, K\),
- Dòng thứ hai chứa \(N\) số nguyên dương \(A_1, A_2,…, A_N\).
Output
- Một dòng chứa dãy số nhỏ thứ \(K\) trong dãy.
Example
Test 1
Input
6 4
91 451 43 3 452 54
Output
91
Bình luận
include<bits/stdc++.h>
using namespace std;
define N 11234567
long long b,n,k,a[N],i;
int main()
{
//freopen("a.inp","r",stdin);
//freopen("a.out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>n>>k;
for(i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+1+n);
cout<<a[k];
}
800 điểm free
mình thấy có vẻ test hơi yếu, nếu chỉ sort như bình thường rồi in ra phần tử thứ k trong mảng đã sort thì AC cả bài, nhưng nếu làm vậy mà gặp trường hợp nhiều số giống nhau là đi luôn
n, k=map(int, input().split())
a=list(map(int, input().split()))
a.sort()
print(*a[k-1:k])
dễ lám
include <bits/stdc++.h>
using namespace std;
long long n,a[10000010],k,i;
int main()
{
cin>>n>>k;
for(i=1;i<=n;i++) cin>>a[i];
sort (a+1,a+n+1);
cout<<a[k];
}
This comment is hidden due to too much negative feedback. Click here to view it.
This comment is hidden due to too much negative feedback. Click here to view it.
This comment is hidden due to too much negative feedback. Click here to view it.
This comment is hidden due to too much negative feedback. Click here to view it.
This comment is hidden due to too much negative feedback. Click here to view it.