Submission #626003

#TimeUsernameProblemLanguageResultExecution timeMemory
626003aryan12Catfish Farm (IOI22_fish)C++17
6 / 100
131 ms13556 KiB
#include "fish.h"

#include <bits/stdc++.h>
using namespace std;

// subtask 2

bool cmp(array<int, 3> a, array<int, 3> b)
{
    if(a[1] != b[1]) return a[1] < b[1];
    return a[0] > b[0];
}

long long max_weights(int N, int M, std::vector<int> X, 
    std::vector<int> Y, std::vector<int> W) {
    long long ans1 = 0, ans2 = 0;
    for(int i = 0; i < W.size(); i++)
    {
        if(X[i] == 0) ans1 += W[i];
        else ans2 += W[i];
    }
    if(N == 2)
    {
        return max(ans1, ans2);
    }
    vector<array<int, 3> > vect;
    for(int i = 0; i < W.size(); i++)
    {
        vect.push_back({X[i], Y[i], W[i]});
    }
    sort(vect.begin(), vect.end(), cmp);
    long long cur_ans = max(ans1, ans2);
    ans1 = 0;
    for(int i = 0; i < vect.size(); i++)
    {
        if(vect[i][0] == 0)
        {
            ans1 += vect[i][2];
        }
        else
        {
            ans2 -= vect[i][2];
        }
        cur_ans = max(cur_ans, ans1 + ans2);
    }
    return cur_ans;
}

Compilation message (stderr)

fish.cpp: In function 'long long int max_weights(int, int, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     for(int i = 0; i < W.size(); i++)
      |                    ~~^~~~~~~~~~
fish.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < W.size(); i++)
      |                    ~~^~~~~~~~~~
fish.cpp:34:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i = 0; i < vect.size(); i++)
      |                    ~~^~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...