#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
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]++]];
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
4660 KB |
Output is correct |
2 |
Correct |
44 ms |
5588 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
88 ms |
14316 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '0' |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
73 ms |
10004 KB |
Output is correct |
3 |
Correct |
92 ms |
11808 KB |
Output is correct |
4 |
Correct |
35 ms |
5764 KB |
Output is correct |
5 |
Correct |
41 ms |
6600 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
308 KB |
Output is correct |
9 |
Correct |
1 ms |
308 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
43 ms |
5736 KB |
Output is correct |
13 |
Correct |
42 ms |
6576 KB |
Output is correct |
14 |
Correct |
35 ms |
5704 KB |
Output is correct |
15 |
Correct |
42 ms |
6092 KB |
Output is correct |
16 |
Correct |
40 ms |
5680 KB |
Output is correct |
17 |
Correct |
42 ms |
6072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '3', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
1st lines differ - on the 1st token, expected: '882019', found: '0' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
4660 KB |
Output is correct |
2 |
Correct |
44 ms |
5588 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Incorrect |
88 ms |
14316 KB |
1st lines differ - on the 1st token, expected: '149814460735479', found: '0' |
6 |
Halted |
0 ms |
0 KB |
- |