#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct Mine
{
int position, energy, gold;
};
vector<long long> PosibleIndexes;
int normalize(long long index)
{
int rez=0;
for(int i=20; i>=0; i--)
{
if((rez^(1<<i))<PosibleIndexes.size() && PosibleIndexes[rez^(1<<i)]<=index)
{
rez^=(1<<i);
}
}
return rez+1;
}
void create_normalization(int n, Mine Mines[], long long SumEnergy[])
{
for(int i=1; i<=n; i++)
{
PosibleIndexes.push_back(1LL*Mines[i].position-SumEnergy[i-1]);
PosibleIndexes.push_back(1LL*Mines[i].position-SumEnergy[i]);
}
sort(PosibleIndexes.begin(), PosibleIndexes.end());
}
class FenwickTree
{
private:
int F[200005];
int MAX_FENWICK;
public:
FenwickTree(int sz)
{
MAX_FENWICK=sz;
for(int i=1; i<=MAX_FENWICK; i++)
{
F[i]=100001;
}
}
void update(long long pos, int val)
{
pos=normalize(pos);
while(pos>0)
{
F[pos]=min(F[pos],val);
pos=pos-(pos&(pos^(pos-1)));
}
}
int query(long long pos)
{
pos=normalize(pos);
int rez=100001;
while(pos<=MAX_FENWICK)
{
rez=min(rez,F[pos]);
pos=pos+(pos&(pos^(pos-1)));
}
return rez;
}
};
Mine Mines[100005];
long long SumEnergy[100005];
long long SumGold[100005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1; i<=n; i++)
{
cin>>Mines[i].position>>Mines[i].gold>>Mines[i].energy;
}
for(int i=1; i<=n; i++)
{
SumEnergy[i]=SumEnergy[i-1]+Mines[i].energy;
SumGold[i]=SumGold[i-1]+Mines[i].gold;
}
create_normalization(n, Mines, SumEnergy);
FenwickTree FT=FenwickTree(2*n);
long long rez=0;
for(int i=1; i<=n; i++)
{
FT.update(1LL*Mines[i].position-SumEnergy[i-1],i);
int bestLeft=FT.query(1LL*Mines[i].position-SumEnergy[i]);
rez=max(rez,SumGold[i]-SumGold[bestLeft-1]);
}
cout<<rez<<"\n";
return 0;
}
Compilation message
divide.cpp: In function 'int normalize(long long int)':
divide.cpp:19:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | if((rez^(1<<i))<PosibleIndexes.size() && PosibleIndexes[rez^(1<<i)]<=index)
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1096 KB |
Output is correct |
9 |
Correct |
1 ms |
1096 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1096 KB |
Output is correct |
9 |
Correct |
1 ms |
1096 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
2 ms |
1240 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
1 ms |
1100 KB |
Output is correct |
21 |
Correct |
2 ms |
1232 KB |
Output is correct |
22 |
Correct |
2 ms |
1144 KB |
Output is correct |
23 |
Correct |
3 ms |
1488 KB |
Output is correct |
24 |
Correct |
3 ms |
1496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
1 ms |
1100 KB |
Output is correct |
4 |
Correct |
1 ms |
1100 KB |
Output is correct |
5 |
Correct |
1 ms |
1100 KB |
Output is correct |
6 |
Correct |
1 ms |
1100 KB |
Output is correct |
7 |
Correct |
1 ms |
1100 KB |
Output is correct |
8 |
Correct |
1 ms |
1096 KB |
Output is correct |
9 |
Correct |
1 ms |
1096 KB |
Output is correct |
10 |
Correct |
1 ms |
1100 KB |
Output is correct |
11 |
Correct |
1 ms |
1100 KB |
Output is correct |
12 |
Correct |
1 ms |
1100 KB |
Output is correct |
13 |
Correct |
1 ms |
1100 KB |
Output is correct |
14 |
Correct |
1 ms |
1100 KB |
Output is correct |
15 |
Correct |
1 ms |
1100 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
1 ms |
1100 KB |
Output is correct |
18 |
Correct |
2 ms |
1240 KB |
Output is correct |
19 |
Correct |
1 ms |
1100 KB |
Output is correct |
20 |
Correct |
1 ms |
1100 KB |
Output is correct |
21 |
Correct |
2 ms |
1232 KB |
Output is correct |
22 |
Correct |
2 ms |
1144 KB |
Output is correct |
23 |
Correct |
3 ms |
1488 KB |
Output is correct |
24 |
Correct |
3 ms |
1496 KB |
Output is correct |
25 |
Correct |
3 ms |
1484 KB |
Output is correct |
26 |
Correct |
6 ms |
1868 KB |
Output is correct |
27 |
Correct |
6 ms |
1872 KB |
Output is correct |
28 |
Correct |
28 ms |
4632 KB |
Output is correct |
29 |
Correct |
25 ms |
4932 KB |
Output is correct |
30 |
Correct |
57 ms |
8928 KB |
Output is correct |
31 |
Correct |
50 ms |
7744 KB |
Output is correct |
32 |
Correct |
53 ms |
7792 KB |
Output is correct |
33 |
Correct |
51 ms |
7680 KB |
Output is correct |
34 |
Correct |
53 ms |
7644 KB |
Output is correct |
35 |
Correct |
52 ms |
8128 KB |
Output is correct |
36 |
Correct |
59 ms |
8304 KB |
Output is correct |