#include #include int n, p[10000], tot, i; int va(int b) { int t=tot; for(i=0; i { if(p[i]<=b) { t-=p[i]; } else { t-=b; } } if(t<0) { return 0; } else { return 1; } } int main() { int max=-999, sum=0; int left, right, mid; scanf("%d", &n); for(i=0; i { scanf("%d", &p[i]); sum+=p[i]; if(p[i]>max) { max=p[i]; } } scanf("%d", &tot); if(sum<=tot) { printf("%d", max); return 0; } left=1; right=tot; while(left<=right) { mid=(left+right)/2; if(va(mid)) { left=mid+1; } else { right=mid-1; } } printf("%d", right); return 0; } ---- 수정본 ---- #include #include int n, p[10000], tot, i; int va(int b) { int t=tot; for(i=0; i { if(p[i]<=b) t-=p[i]; else t-=b; } if(t<0) return 0; else return 1; } int main() { int max=-999, sum=0; int left, right, mid; freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); scanf("%d", &n); for(i=0; i { scanf("%d", &p[i]); sum+=p[i]; if(p[i]>max) max=p[i]; } scanf("%d", &tot); if(sum<=tot) { printf("%d", max); return 0; } left=1; right=tot; while(left<=right) { mid=(left+right)/2; if(va(mid)) left=mid+1; else right=mid-1; } printf("%d", right); return 0; }
|