edu-pi / SOMA

0 stars 0 forks source link

[알고리즘] 5번째 알고리즘 문제 풀기 #46

Closed SongGwanSeok closed 4 months ago

SongGwanSeok commented 4 months ago

📝 Description

무엇을?

왜?

❗️Todo

ETC

기타사항

SongGwanSeok commented 4 months ago
  1. Grumpy Bookstore Owner

    
    int cur = 0;
    
    for(int i = 0; i < grumpy.size(); i++){
        if(grumpy[i] == 0){
            cur += customers[i];
        }
    }
    
    for(int i = 0; i < minutes; i++){
        if(grumpy[i] == 1) {
            cur += customers[i];
        }
    }
    
    int _max = cur;
    int p1 = 0;
    int p2 = minutes;
    while(p2 < grumpy.size()){
        if(grumpy[p1] == 1){
            cur -= customers[p1];
        }
        if(grumpy[p2] == 1){
            cur += customers[p2];
        }
        p1++, p2++;
        _max = max(_max, cur);
    }
    
    return _max;