#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);
#define OYY 1000000005
#define mod 998244353
vector <pair<int,pair<int,int>>> v,v1;
int main(){
faster
v.clear(),v1.clear();
int n,k,m;cin>>n>>k>>m;
int sol=0,sag=0;
for(int i=0;i<m;i++){
int a,b,c;
cin>>a>>b>>c;
if(c>abs(k-a)){
if(k-a>=0){
v.push_back({a,{b,c}});
sol+=b;
}
else {
v1.push_back({a,{b,c}});
sag+=b;
}
}
}
/*/ sort(v.begin(),v.end());
sort(v.begin(),v.end());*/
//for(int i=0;i<v.size();i++)cout<<v[i].first<<" "<<v[i].second.first<< " "<<v[i].second.second<<endl;
int t=abs((v[0].first)-k)*2;
//cout<<t<<endl;
for(int i=0;i<v1.size();i++){
int a=v1[i].first;
a=abs(k-a);
int b=v1[i].second.first;
int c=v1[i].second.second;
if(t+a>=c)continue;
sol+=b;
}
int gec=v1.size();
t=abs((v1[gec-1].first)-k)*2;
//cout<<t<<endl;
for(int i=0;i<v.size();i++){
int a=v[i].first;
a=abs(k-a);
int b=v[i].second.first;
int c=v[i].second.second;
if(t+a>=c)continue;
sag+=b;
}
//cout<<sol<<" "<<sag<<endl;
cout<<max(sol,sag)<<'\n';
return 0;
}
Compilation message
go.cpp: In function 'int main()':
go.cpp:33:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i=0;i<v1.size();i++){
| ~^~~~~~~~~~
go.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for(int i=0;i<v.size();i++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
488 KB |
Execution killed with signal 11 |
2 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
3 |
Runtime error |
1 ms |
340 KB |
Execution killed with signal 11 |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |