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 "fish.h"
#include <vector>
#define ll long long
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
#define ff first
#define ss second
const int maxn = 3e5 + 10;
int n,m;
ii a[maxn]; int w[maxn];
bool cmp(int x, int y)
{
return a[x]<a[y];
}
ll sub2(vector <int> X, vector <int> Y, vector <int> W)
{
ll ans=0;
ll sum=0;
vector <int> id[2];
for (int i=0; i<m; i++)
if (X[i]==0) sum+=W[i], id[0].push_back(i);
ans=sum;
sum=0;
for (int i=0; i<m; i++)
if (X[i]==1) sum+=W[i], id[1].push_back(i);
ans=max(ans,sum);
if (n==2) return ans;
sort(id[0].begin(),id[0].end(),cmp);
sort(id[1].begin(),id[1].end(),cmp);
int it[2];
it[0]=it[1]=0;
for (int y=0; y<n; y++)
{
while (it[0]<id[0].size()&&a[id[0][it[0]]].ss <= y) sum+=w[id[0][it[0]++]];
while (it[1]<id[1].size()&&a[id[1][it[1]]].ss <= y) sum-=w[id[1][it[1]++]];
// cerr<<y<<" : "<<sum<<'\n';
ans=max(ans,sum);
}
return ans;
}
long long max_weights(int N, int M, std::vector<int> X, std::vector<int> Y,
std::vector<int> W) {
n=N; m=M;
for (int i=0; i<m; i++) a[i]={X[i],Y[i]}, w[i]=W[i];
return sub2(X,Y,W);
}
Compilation message (stderr)
fish.cpp: In function 'long long int sub2(std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:37:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | while (it[0]<id[0].size()&&a[id[0][it[0]]].ss <= y) sum+=w[id[0][it[0]++]];
| ~~~~~^~~~~~~~~~~~~
fish.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while (it[1]<id[1].size()&&a[id[1][it[1]]].ss <= y) sum-=w[id[1][it[1]++]];
| ~~~~~^~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |