fork download
  1. /* AUTHOR: TUAN ANH - BUI */
  2. // ~~ icebear ~~
  3. #include <bits/stdc++.h>
  4. using namespace std;
  5.  
  6. typedef long long ll;
  7. typedef pair<int, int> ii;
  8. typedef pair<int, ii> iii;
  9.  
  10. template<class X, class Y>
  11. bool minimize(X &x, const Y &y) {
  12. if (x > y) return x = y, true;
  13. return false;
  14. }
  15.  
  16. template<class X, class Y>
  17. bool maximize(X &x, const Y &y) {
  18. if (x < y) return x = y, true;
  19. return false;
  20. }
  21.  
  22. #define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
  23. #define FORR(i,a,b) for(int i=(a); i>=(b); --i)
  24. #define REP(i, n) for(int i=0; i<(n); ++i)
  25. #define RED(i, n) for(int i=(n)-1; i>=0; --i)
  26. #define MASK(i) (1LL << (i))
  27. #define BIT(S, i) (((S) >> (i)) & 1)
  28. #define mp make_pair
  29. #define pb push_back
  30. #define fi first
  31. #define se second
  32. #define all(x) x.begin(), x.end()
  33. #define task "icebear"
  34. /*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN VOI26 */
  35.  
  36. const int MOD = 1e9 + 7;
  37. const int inf = (int)1e9 + 27092008;
  38. const ll INF = (ll)1e18 + 27092008;
  39. const int N = 1000 + 5;
  40. int n, a[N][N];
  41.  
  42. void init(void) {
  43. cin >> n;
  44. FOR(i, 1, n) FOR(j, 1, n)
  45. cin >> a[i][j];
  46. }
  47.  
  48. void process(void) {
  49. FOR(i, 1, n) FOR(j, 1, n) if (a[i][j] < 0) {
  50. cout << "NO";
  51. exit(0);
  52. }
  53. FOR(i, 1, n) {
  54. int sum = 0;
  55. FOR(j, 1, n) if (i != j)
  56. sum += a[i][j];
  57. if (a[i][i] < sum) {
  58. cout << "NO";
  59. exit(0);
  60. }
  61. }
  62.  
  63. int cnt = 0;
  64. FOR(i, 1, n) {
  65. int sum = 0;
  66. FOR(j, 1, n) if (i != j)
  67. sum += a[i][j];
  68. if (a[i][i] > sum) cnt++;
  69. }
  70. if (cnt == 0) cout << "NO";
  71. else {
  72. cout << "YES\n" << cnt << '\n';
  73. }
  74. }
  75.  
  76. int main() {
  77. ios_base::sync_with_stdio(0);
  78. cin.tie(0); cout.tie(0);
  79. if (fopen(task".inp", "r")) {
  80. freopen(task".inp", "r", stdin);
  81. freopen(task".out", "w", stdout);
  82. }
  83. int tc = 1;
  84. // cin >> tc;
  85. while(tc--) {
  86. init();
  87. process();
  88. }
  89. return 0;
  90. }
  91.  
  92.  
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
NO