View Code of Problem 3802

#include <stdio.h>  
#include <string.h>
#include <algorithm>
using namespace std;

int nt, mt[110];  

int main(){  
    int n, W, H;  
    while(~scanf("%d%d%d", &n, &W, &H)){  
        memset(mt, 0, sizeof(mt));  
        int sum = 0;  
        for(int i = 0; i < W; i++)
            mt[i] = -H;  

        for(int i = W; i < n + W; i++){  
            scanf("%d", &nt);  
            sum += nt;  
            mt[i] = nt - H;  
        }  
        for(int i = n + W; i < n + W + W; i++)  
            mt[i] = -H;
              
        if(sum < W * H){  
            printf("-1\n");  
            continue;  
        }  
  
        int ans = W * H, l = W * H, r = 0;  
        for(int i = W; i < n + W + W; i++){  
            if(mt[i - W] < 0) 
                l += mt[i - W];  
            else
                r -= mt[i - W];  
            if(mt[i] < 0)
                l -= mt[i];  
            else
                r += mt[i];  
            ans = min(ans, max(l, r));  
        }  
        printf("%d\n",ans);  
    }  
    return 0;  
} 

Double click to view unformatted code.


Back to problem 3802