Pagini recente » Cod sursa (job #2817112) | Cod sursa (job #1586635) | Cod sursa (job #2705099) | Cod sursa (job #1894240) | Cod sursa (job #1016313)
#include<iostream>
#include<fstream>
using namespace std;
int main(){unsigned n,k,e,i,j,max,a;
ifstream f("sdo.in");
f>>n>>k; unsigned v[n+1],c[k+1];
for(i=1;i<=n;i++){f>>v[i]; if(i<=k)c[i]=v[i];}
f.close();
max=c[1]; j=1;
for(e=2;e<=k;e++) if(c[e]>max) {max=c[e]; j=e;}
a=c[j]; c[j]=c[1]; c[1]=a; j=1;
for(i=k+1;i<=n;i++){
if(v[i]<c[1]){c[1]=v[i]; max=v[i];
for(e=2;e<=k;e++) if(c[e]>max) {max=c[e]; j=e;}
a=c[j]; c[j]=c[1]; c[1]=a; j=1; max=c[1]; }}
max=c[1];
for(i=2;i<=k;i++)if(max<c[i])max=c[i];
ofstream g("sdo.out");
g<<max;
g.close();
return 0;}