Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <algorithm>
- #include <functional>
- #include <vector>
- #include <string>
- #include <set>
- #include <map>
- #include <deque>
- #include <queue>
- #define ft first
- #define sc second
- #define mp make_pair
- #define pb push_back
- #define all(x) (x).begin(), (x).end()
- #define sz(a) (int)(a).size()
- #define forn(i, n) for (int i = 0; i < (n); i++)
- #define fore(i, f, t) for (int i = (f); i < (t); i++)
- #define ll long long
- #define pii pair<int, int>
- #define pll pair<ll, ll>
- using namespace std;
- const int N = 2010;
- int a[N][N], cnt[N];
- ll sum[N];
- int main(){
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif
- int n, k;
- scanf("%d%d", &n, &k);
- forn(i, n - 1)
- fore(j, i + 1, n){
- scanf("%d", &a[i][j]);
- a[j][i] = a[i][j];
- if (a[i][j] != -1){
- cnt[i]++;
- cnt[j]++;
- }
- }
- forn(i, n)
- forn(j, n)
- sum[i] += max(a[i][j], 0);
- ll ans = 0, m = 0;
- forn(i, n)
- if (cnt[i] >= k){
- ans += sum[i] * max(1ll, 1ll * (cnt[i] - k) * (cnt[i] - k + 1) / 2);
- m += 1ll * (cnt[i] - k + 1) * (cnt[i] - k + 2) / 2;
- }
- if (m == 0)
- printf("0\n");
- else
- printf("%I64d\n", ans / m);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement