import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class SubPrime {
public static void main(String[] args) throws Exception {
Reader.init(System.in);
int noOfBanks = Reader.nextInt();
int noOfDebetures = Reader.nextInt();
int tempDebtor;
int tempCreditor;
int tempValue;
boolean flag;
while(noOfBanks != 0 && noOfDebetures != 0) {
int[] bankAccount = new int[noOfBanks];
for(int i = 0; i < noOfBanks; i++) {
bankAccount[i] = Reader.nextInt();
}
for(int i = 0; i < noOfDebetures; i++) {
tempDebtor = Reader.nextInt();
tempCreditor = Reader.nextInt();
tempValue = Reader.nextInt();
bankAccount[tempDebtor - 1] -= tempValue;
bankAccount[tempCreditor - 1] += tempValue;
}
flag = true;
for(int i = 0; i < noOfBanks; i++) {
if(bankAccount[i] < 0) {
flag = false;
break;
}
}
if(flag) System.out.println("S");
else System.out.println("N");
noOfBanks = Reader.nextInt();
noOfDebetures = Reader.nextInt();
}
}
}
/** Class for buffered reading int and double values */
/** http://www.cpe.ku.ac.th/~jim/java-io.html */
class Reader {
static BufferedReader reader;
static StringTokenizer tokenizer;
/** call this method to initialize reader for InputStream */
static void init(InputStream input) {
reader = new BufferedReader(new InputStreamReader(input));
tokenizer = new StringTokenizer("");
}
/** get next word */
static String next() throws IOException {
while ( ! tokenizer.hasMoreTokens() ) {
//TODO add check for eof if necessary
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
static int nextInt() throws IOException {
return Integer.parseInt( next() );
}
static double nextDouble() throws IOException {
return Double.parseDouble( next() );
}
}
10/08/2013
11679 - Sub-prime - Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment