#include <bits/stdc++.h>
using namespace std;
#define all(a) a.begin(), a.end()
#define Base 311
#define endl '\n'
#define fi first
#define fii(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define fill(a,n) memset(a, n, sizeof(a));
#define getbit(i, j) ((i >> j) & 1)
#define minimize(x, y) x = (x > y ? y : x)
#define maximize(x, y) x = (x < y ? y : x)
#define ins insert
// #define int long long
#define ll long long
#define maxn 1000006
#define MOD 1000000007
#define name "file"
#define pb push_back
#define pii pair< int, int >
#define pll pair< long long , long long >
#define re return
#define sz(x) int(x.size())
#define se second
#define ull unsigned long long
void ctime () {
cerr << "\n" << "\nTime elapsed: " << 1000 * clock () / CLOCKS_PER_SEC << "ms\n" ;
}
void iof () {
if ( fopen ( name ".inp" , "r" ))
{
freopen ( name ".inp" , "r" , stdin );
freopen ( name ".out" , "w", stdout );
}
ios_base :: sync_with_stdio ( 0 );
cin . tie ( NULL ), cout . tie ( NULL );
}
struct mine {
ll x, g, e;
};
ll energy[maxn];
mine mines[maxn];
ll gold[maxn];
map<ll, ll> mp;
int main(){
iof();
int n;
cin >> n;
ll ans = 0;
fii(i, 1, n)
{
ll u, v, val;
cin >> u >> v >> val;
mines[i] = {u, v, val};
energy[i] = energy[i - 1] + val;
gold[i] = gold[i - 1] + v;
if (mp[energy[i] - u] == 0) mp[energy[i - 1] - u] = i;
else
{
ans = max(ans, gold[i] - gold[mp[energy[i - 1] - u]]);
}
if (val == 1) ans = max(ans, v);
}
cout << ans;
ctime();
re 0;
}
Compilation message
divide.cpp: In function 'void iof()':
divide.cpp:35:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | freopen ( name ".inp" , "r" , stdin );
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:36:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | freopen ( name ".out" , "w", stdout );
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |