1.

/**
* ACM Training 2009
* ACM Problem # 19.09. "Sub Prime"
* Link: http://uva.onlinejudge.org/contests/227-44fb9aab/11679.pdf
*
* @author Felix Dietrich
* @version 1.0, 09/20/2009
*
* Methode: Simulation
* Status : Accepted
* Runtime: 0.160
*/

import java.util.*;

public class Main
{


public static class Bank
{
int currentmoney;

public Bank(int money)
{
currentmoney = money;
}

}

public static void main(String... args)
{
Scanner sc = new Scanner(System.in);
int B,N;
boolean bailoutNecessary = false;
List<Bank> banklist = new ArrayList<Bank>();

while(true)
{
banklist.clear();
bailoutNecessary = false;

B = sc.nextInt();
N = sc.nextInt();

if(B == 0 && N == 0)
return;

for(int b=0; b<B; b++)
banklist.add(new Bank(sc.nextInt()));

// if a bank is in debt at another bank, give the money back!
for(int n=0; n<N; n++)
{
Bank debtor = banklist.get(sc.nextInt()-1);
Bank creditor = banklist.get(sc.nextInt()-1);
int value = sc.nextInt();
debtor.currentmoney -= value;
creditor.currentmoney += value;
}

for(Bank b: banklist)
if(b.currentmoney < 0)
{
bailoutNecessary = true;
break;
}
// if any bank has a negative amount of money, i.e. is in debt
if(bailoutNecessary)
System.out.println("N");
else
System.out.println("S");
}
}
}



2.

/**
* ACM Training 2009
* ACM Problem #11679 - Sub-prime
* Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=78&page=show_problem&problem=2726
*
* @author Dennis Wilfert
* @version 1.0, 09/20/2009
*
* Status : Accepted
* Runtime: 0.184
*/
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

public static void main(String[] args) throws IOException {

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
PrintWriter writer = new PrintWriter(new BufferedOutputStream(System.out));
StringTokenizer token;

token = new StringTokenizer(reader.readLine());
int banks = Integer.parseInt(token.nextToken());
int debentures = Integer.parseInt(token.nextToken());

int i, b1, b2, m;
int[] bank;
boolean f;
while (banks != 0) {

bank = new int[banks];
f = true;
token = new StringTokenizer(reader.readLine());
// Geldreserven der jeweiligen Banken eintragen
for(i = 0; i < banks; i++){
bank[i] = Integer.parseInt(token.nextToken());
}

while(debentures > 0){

token = new StringTokenizer(reader.readLine());

b1 = Integer.parseInt(token.nextToken())-1;
b2 = Integer.parseInt(token.nextToken())-1;
m = Integer.parseInt(token.nextToken());
// m bei der Schuldnerbank abziehen
bank[b1] -= m;
// m bei der Kreditbank dazuzählen
bank[b2] += m;

debentures--;
}
// Ist eine Bank im minus wird N ausgegeben
for(i = 0; i < banks; i++){
if(bank[i]<0){
f = false;
break;
}
}

writer.println(f ? 'S' : 'N');

token = new StringTokenizer(reader.readLine());
banks = Integer.parseInt(token.nextToken());
debentures = Integer.parseInt(token.nextToken());
}

writer.flush();
}
}