Submission #17459

#TimeUsernameProblemLanguageResultExecution timeMemory
17459azecoderUFO (IZhO14_ufo)C++98
20 / 100
2000 ms9704 KiB
#include <iostream>
#include <algorithm>

#define f first
#define s second
 
using namespace std;
 
int n , m , R , k , p , x, h, ans ;

char ch ;
 
int main () {
      
    cin >> n >> m >> R >> k >> p ;
    
    int a[n + 1][m + 1] ;
    
    for ( int i = 1 ; i <= n ; i ++ )
    	for ( int j = 1 ; j <= m ; j ++ ) cin >> a[i][j] ;
    
    for ( int l = 0 ; l < k ; l ++ ) {
    	
        cin >> ch >> x >> h ;
        
		int r = R ;
		
        if ( ch == 'N' ) for ( int i = 1; i <= n; i ++ )
			if ( r && a[i][x] >= h) a[i][x] --, r -- ;
            else if ( !r ) break;
            
        if ( ch == 'W' ) for ( int i = 1; i <= m; i ++ )
			if ( r && a[x][i] >= h ) a[x][i] --, r -- ;
            else if ( !r ) break;
            
        if ( ch == 'E' ) for ( int i = n; i >= 1; i -- )
			if ( r && a[x][i] >= h ) a[x][i] --, r -- ;
    		else if ( !r ) break;
    		
        if ( ch == 'S' ) for ( int i = m; i >= 1; i -- )
			if ( r && a[i][x] >= h ) a[i][x] --, r -- ;
        	else if (!r) break;
        	
    }
    
    for ( int i = 1 ; i <= n - p + 1 ; i ++ ) {
        
		for ( int j = 1 ; j <= m - p + 1 ; j++) {
            
			int c = 0;
            
			for ( int k = i ; k < i + p ; k ++ )
                for ( int l = j ; l < j + p ; l ++ )
                    c += a[k][l];
      
	        ans = max ( ans , c ) ;
      
	    }
        
    }
    
    cout << ans << endl;
 
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...