예산 |
좋아요:0 | ||||
---|---|---|---|---|---|
작성자 | 김선형 | 등록일 | 14.06.09 | 조회수 | 85 |
#include #include int n,str[10000],m,i; int possible(int a) { int total=m; for(i=0; i if(str[i]>a) total-=a; else total-=str[i]; } if(total<0) return 0; else return 1; } int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); int sum=0,max,left,mid,right; scanf("%d",&n); for(i=0; i scanf("%d",&str[i]); sum+=str[i]; } scanf("%d",&m); if(sum<=m) { max=str[0]; for(i=1; i if(str[i]>max) max=str[i]; } printf("%d",max); } else { left=1; right=m; while(left<=right) { mid=(left+right)/2; if(possible(mid)) left=mid+1; else right=mid-1; } printf("%d",right); } } |
이전글 | 예산 |
---|---|
다음글 | 예산 |