CSES - Aalto Competitive Programming 2024 - wk4 - Wed - Results
Submission details
Task:Box Stack II
Sender:aalto2024d_006
Submission time:2024-09-25 17:20:55 +0300
Language:C++ (C++11)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int main()':
input/code.cpp:57:25: error: expected '}' at end of input
   57 |     cout << max << endl;
      |                         ^
input/code.cpp:19:1: note: to match this '{'
   19 | {
      | ^

Code

#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
 
struct Box
{
    int h, w, d;
};
 
bool compare(const Box &a, const Box &b)
{
    return (a.w * a.d) > (b.w * b.d);
}
 
int main()
{
    int n;
    cin >> n;
 
    vector<Box> boxes(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> boxes[i].w >> boxes[i].d >> boxes[i].h;
    }
 
	sort(boxes.begin(), boxes.end(), compare);
 
    vector<int> msh(n);
    for (int i = 0; i < n; i++)
    {
        msh[i] = boxes[i].h;
    }
 
    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < i; j++)
        {
            if (boxes[i].w <= boxes[j].w && boxes[i].d <= boxes[j].d && msh[i] < msh[j] + boxes[i].h)
            {
                msh[i] = msh[j] + boxes[i].h;
            }
        }
    }
 
    int max = -1;
    for (int i = 0; i < n; i++)
    {
        if (max < msh[i])
        {
            max = msh[i];
        }
    }
 
    cout << max << endl;