# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302540 | circlethm | Carnival Tickets (IOI20_tickets) | C++17 | 3070 ms | 384 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "tickets.h"
#include <vector>
#include <cmath>
#include <iostream>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
ll get_sum(vi elements, int b)
{
ll total = 0;
int n = elements.size();
for (int i = 0; i < n; i++)
{
total += abs(b - elements[i]);
}
return total;
}
ll find_min_sum(vi elements, int max)
{
ll min_sum = 10E11;
int opt_b = 0;
for (int b = 0; b < max; b++)
{
ll sum = get_sum(elements, b);
// cout << "b: " << sum << endl;
if (sum < min_sum)
{
min_sum = sum;
opt_b = b;
}
}
// cout << "b: " << opt_b << " -> " << min_sum << endl;
return min_sum;
}
long long find_maximum(int k, std::vector<std::vector<int>> x)
{
// int n = x.size();
// int m = x[0].size();
// std::vector<std::vector<int>> answer;
// for (int i = 0; i < n; i++) {
// std::vector<int> row(m);
// for (int j = 0; j < m; j++) {
// if (j < k) {
// row[j] = j;
// } else {
// row[j] = -1;
// }
// }
// answer.push_back(row);
// }
// allocate_tickets(answer);
// return 1;
int n = x.size();
// int m = x[0].size();
vi elements;
vector<vi> answer;
int max = -1;
for (int i = 0; i < n; i++)
{
vi row = {0};
answer.push_back(row);
int current_el = x[i][0];
if (current_el > max)
max = current_el;
elements.push_back(current_el);
}
allocate_tickets(answer);
return find_min_sum(elements, max);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |