#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 pair <ll,ll> ii;
typedef vector <ii> vii;
void printVct(vi &v, string s = ""){
cout<<s<<": ";
for (ll i=0; i<sz(v); i++){
cout<<v[i]<<" ";
}
cout<<endl;
}
void kadane(vi &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){
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 <vi> arr(n, vi(2,0));
for (ll i =0; i<m; i++){
arr[Y[i]][X[i]] = W[i];
}
vi v(n);
for (ll i =0; i<n; i++){
ll dif = arr[i][0] - arr[i][1];
v[i] = dif;
}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
7344 KB |
Output is correct |
2 |
Correct |
29 ms |
8392 KB |
Output is correct |
3 |
Correct |
6 ms |
6100 KB |
Output is correct |
4 |
Correct |
6 ms |
6100 KB |
Output is correct |
5 |
Runtime error |
82 ms |
25720 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
48 ms |
9324 KB |
1st lines differ - on the 1st token, expected: '40604614618209', found: '40665029450929' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
6100 KB |
Output is correct |
2 |
Runtime error |
9 ms |
11468 KB |
Execution killed with signal 6 |
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 |
6 ms |
6100 KB |
Output is correct |
2 |
Runtime error |
9 ms |
11468 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
7344 KB |
Output is correct |
2 |
Correct |
29 ms |
8392 KB |
Output is correct |
3 |
Correct |
6 ms |
6100 KB |
Output is correct |
4 |
Correct |
6 ms |
6100 KB |
Output is correct |
5 |
Runtime error |
82 ms |
25720 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |