376B - IOU - CodeForces Solution


implementation *1300

Please click on ads to support us..

Python Code:

n, m = map(int, input().split())
debts = [0] * n
for _ in range(m):
    minus, plus, value = map(int, input().split())
    debts[minus - 1] -= value
    debts[plus - 1] += value

print(sum([debt for debt in debts if debt > 0]))

C++ Code:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    map<long long,long long>mp;
    for(int i=0;i<m;i++)
    {
        long long x,y,z;
        cin>>x>>y>>z;
        mp[x]-=z;
        mp[y]+=z;
    }
    long long ans=0;
    for(auto it:mp)
    {
        if(it.second>=0)
        {
            ans+=it.second;
        }

    }
    cout<<ans;
}


Comments

Submit
0 Comments
More Questions

766A - Mahmoud and Longest Uncommon Subsequence
701B - Cells Not Under Attack
702A - Maximum Increase
1656D - K-good
1426A - Floor Number
876A - Trip For Meal
1326B - Maximums
1635C - Differential Sorting
961A - Tetris
1635B - Avoid Local Maximums
20A - BerOS file system
1637A - Sorting Parts
509A - Maximum in Table
1647C - Madoka and Childish Pranks
689B - Mike and Shortcuts
379B - New Year Present
1498A - GCD Sum
1277C - As Simple as One and Two
1301A - Three Strings
460A - Vasya and Socks
1624C - Division by Two and Permutation
1288A - Deadline
1617A - Forbidden Subsequence
914A - Perfect Squares
873D - Merge Sort
1251A - Broken Keyboard
463B - Caisa and Pylons
584A - Olesya and Rodion
799A - Carrot Cakes
1569B - Chess Tournament