Submission #722034

#TimeUsernameProblemLanguageResultExecution timeMemory
722034danikoynovCarnival Tickets (IOI20_tickets)C++14
27 / 100
484 ms55952 KiB
#include "tickets.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int maxn = 1510;

int N, M, K, used[maxn][maxn];
vector < vector < int > > answer;

struct element
{
    ll max_pos, min_pos, delta, row;

    bool operator < (const element &e) const
    {
        return delta < e.delta;
    }
};

long long find_maximum(int k, vector < vector < int > > x) {
    N = x.size();
    M = x[0].size();
    K = k;
    answer.resize(N);
	for (int i = 0; i < N; i++) {
		answer[i].resize(M, - 1);
	}

	ll max_prize = 0;
    for (int round = 0; round < k; round ++)
    {
        vector < element > arr;
        for (int i = 0; i < N; i ++)
        {
            element cur;
            cur.row = i;
            cur.min_pos = cur.max_pos = 0;
            while(used[i][cur.min_pos] == 1)
                cur.min_pos ++;
            cur.max_pos = cur.min_pos;
            for (int j = 0; j < M; j ++)
            {
                if (used[i][j] == 1)
                    continue;
                if (x[i][j] < x[i][cur.min_pos])
                    cur.min_pos = j;
                if (x[i][j] > x[i][cur.max_pos])
                    cur.max_pos = j;
            }
            ///cout << "here " << round << " " << cur.row << " " << cur.max_pos << " " << cur.min_pos << endl;
            cur.delta =  (x[cur.row][cur.max_pos] + x[cur.row][cur.min_pos]);
            arr.push_back(cur);
        }

        sort(arr.begin(), arr.end());
        for (int i = 0; i < N; i ++)
        {
            element cur = arr[i];
            if (i < N / 2)
            {
                max_prize = max_prize - x[cur.row][cur.min_pos];
                ///cout << cur.row << " :: " << cur.min_pos << endl;
                used[cur.row][cur.min_pos] = 1;
                answer[cur.row][cur.min_pos] = round;
            }
            else
            {
                max_prize = max_prize + x[cur.row][cur.max_pos];
                           ///cout << cur.row << " :: " << cur.max_pos << endl;
                used[cur.row][cur.max_pos] = 1;
                answer[cur.row][cur.max_pos] = round;
            }
        }
    }

	allocate_tickets(answer);
	return max_prize;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...