#include "fish.h"
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define sz(x) (ll)x.size()
#define F first
#define S second
#define pb push_back
#define MID ((l+r)/2)
#define dbg(x) cout<<#x<<": "<<x<<endl;
#define dbg2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl;
#define dbg3(x,y,z) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<" "<<#z<<": "<<z<<endl;
typedef vector <ll> vi;
typedef vector <long long > vl;
typedef pair <ll,ll> ii;
typedef vector <ii> vii;
void printVct(vl &v, string s = ""){
cout<<s<<": ";
for (ll i=0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
void kadane(vl &v, ll &x, ll &y){
long long sum = 0, ans = 0;
ll cur_x = 0;
for (ll i =0;i<sz(v); i++){
sum += v[i];
if (sum < 0){
sum = 0;
cur_x = i+1;
}
if (sum > ans){
ans = sum;
x = cur_x;
y = i;
}
}
}
ll n,m;
long long max_weights(int N, int M, vi X, vi Y, vi W) {
n= N, m =M;
long long ans = 0;
//subtask 2
if (n == 2){
return -1;
// cout<<"111"<<endl;
long long a = 0,b = 0;
for (ll i= 0;i<m; i++){
if (X[i] == 0) a += W[i];
else b+= W[i];
}
ans = max(a,b);
}
else{
vector <vl> arr(n, vl(2,0));
for (ll i =0; i<m; i++){
arr[Y[i]][X[i]] = W[i];
}
vl v(n);
for (ll i =0; i<n; i++){
v[i] = arr[i][0] - arr[i][1];
}
ll x =0, y =0;
printVct(v,"v");
kadane(v, x, y);
// dbg3(x,y,ans);
for (ll i =0; i<x; i++) ans += arr[i][1];
for (ll i=x; i<=y; i++) ans += arr[i][0];
for (ll i=y+1; i<n; i++) ans += arr[i][1];
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
8652 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
6740 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
6740 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
29 ms |
8652 KB |
Possible tampering with the output |
2 |
Halted |
0 ms |
0 KB |
- |