結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
|
| 提出日時 | 2018-04-01 21:40:01 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 637 bytes |
| コンパイル時間 | 167 ms |
| コンパイル使用メモリ | 30,976 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-18 12:15:26 |
| 合計ジャッジ時間 | 1,079 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
#include<stdio.h>
#include<stdlib.h>
int main(void){
int n,i,j,l,r,p,t=2,x,L;
int *a,*s;
scanf("%d",&L);
scanf("%d",&n);
a=(int*)malloc(sizeof(int)*n);
s=(int*)malloc(sizeof(int)*n);
s[0]=0;
s[1]=n-1;
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
while(t>0){
t-=2;
i=l=s[t];
j=r=s[t+1];
p=a[i];
while(i<=j){
while(a[i]<p&&i<r) i++;
while(a[j]>=p&&j>l) j--;
if(i<=j){
x=a[i];
a[i]=a[j];
a[j]=x;
i++;
j--;
}
}
if(j>l){
s[t]=l;
s[t+1]=j;
t+=2;
}
if(r>i){
s[t]=i;
s[t+1]=r;
t+=2;
}
}
for(i=0;L>=0&&i<=n;L-=a[i],i++);
printf("%d\n",i-1);
return 0;
}