Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- struct tri{
- int val;
- pair<int,int> p,q;
- };
- bool comp(tri a,tri b){
- return a.val>b.val;
- }
- int main(){
- boost
- int n,k;
- cin>>n>>k;
- int m[n+5][4];
- memset(m,0,sizeof(m));
- vector<tri> pos;
- for(int i=1;i<=n;i++){
- for(int j=1;j<=3;j++){
- cin>>m[i][j];
- }
- }
- for(int i=1;i<=n;i++){
- for(int j=1;j<=3;j++){
- if(i>1) pos.push_back({m[i][j]+m[i-1][j],{i,j},{i-1,j}});
- if(j>1) pos.push_back({m[i][j]+m[i][j-1],{i,j},{i,j-1}});
- }
- }
- sort(pos.begin(),pos.end(),comp);
- int vis[n+5][4];
- memset(vis,0,sizeof(vis));
- int l=pos.size();
- long long int ans=0;
- for(int i=0;i<l and k>0;i++){
- pair<int,int> x=pos[i].p;
- pair<int,int> y=pos[i].q;
- if(vis[x.first][x.second]==0 and vis[y.first][y.second]==0){
- ans+=pos[i].val;
- vis[x.first][x.second]=1;
- vis[y.first][y.second]=1;
- k--;
- }
- }
- cout<<ans<<endl;
- }
Add Comment
Please, Sign In to add comment