#include <stdio.h>
#include <algorithm>

int N, S, task[10][40]; //task[쪽 수][문제 배점]
int PAGE, NUM; //탐색해야하는 쪽 번호, 그 쪽의 문제 번호
int num;
long long max=-1;

void f(int page, int n, int sec, long long score) { //문제 쪽 수, 문제 번호, 남은 시간, 점수 총합
    if(sec<0) return;
    else if(page>PAGE) {
        if(max < score) max=score;
        return;
    }
    else {
        if(n==num) {
            f(page+1, 1, sec-3, score);
            f(page+1, 1, sec-123, score+task[page][n]);
        }
        else {
            f(page, n+1, sec, score);
            f(page, n+1, sec-120, score+task[page][n]);
        }
    }
} 

bool cmp(int a, int b) {
    return a>b;
}

int main() {

    scanf("%d %d", &N, &S);

    PAGE = 5; NUM = 5;
    num=N/S;

    for(int i=1; i<=S; i++)
        for(int j=1; j<=num; j++)
            scanf("%d", &task[i][j]);

    for(int i=1; i<=S; i++)
        std::sort(task[i]+1, task[i]+num+1, cmp);

    for(int i=1; i<=S; i++, puts(""))
        for(int j=1; j<=num; j++)
            printf("%d ", task[i][j]);

    f(1, 1, 1200, 0);

    printf("%lld", max);
    
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: