fork download
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. using namespace std;
  4. using ll = long long;
  5.  
  6. int main(){
  7. ios::sync_with_stdio(false);
  8. cin.tie(NULL);
  9. freopen("Diagonal.inp","r",stdin);
  10. freopen("Diagonal.out","w",stdout);
  11. int n;
  12. cin >> n;
  13. int cnt = 0;
  14. for(int i = 1; i <= n; i++) {
  15. ll sum = 0;
  16. ll diag = 0;
  17. for (int j = 1; j <= n; j++) {
  18. ll x;
  19. cin >> x;
  20. if (x < 0) {
  21. cout << "NO";
  22. return 0;
  23. }
  24. sum += x;
  25. if (i == j) diag = x;
  26. }
  27. if (diag < sum - diag) {
  28. cout << "NO";
  29. return 0;
  30. }
  31. if (diag > sum - diag) cnt++;
  32. }
  33. if(cnt == 0){
  34. cout << "NO";
  35. }else{
  36. cout << "YES\n";
  37. cout << cnt;
  38. }
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty