Advertisement
YEZAELP

PROG-1152: ไฟ (Fire)

Nov 17th, 2021
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int N = 1e3 + 10;
  5. const int N2 = 2e3 + 10;
  6. int ar[N][N];
  7. vector <int> fire[N2];
  8.  
  9. int main(){
  10.  
  11.     int n;
  12.     scanf("%d", &n);
  13.  
  14.     for(int i=1;i<=n;i++){
  15.         for(int j=1;j<=n;j++){
  16.             scanf("%d", &ar[i][j]);
  17.             fire[i+j].push_back(ar[i][j]);
  18.         }
  19.     }
  20.  
  21.     int ans = 0;
  22.     priority_queue <int> pq;
  23.     for(int i=2*n;i>=3;i--){
  24.         for(auto x: fire[i]){
  25.             pq.push(x);
  26.         }
  27.         ans += pq.top();
  28.         pq.pop();
  29.     }
  30.  
  31.     printf("%d", ans);
  32.  
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement