// Codeforces Round #241 (Div. 2) C Booking System
// Problem: http://codeforces.com/contest/416/problem/C
import java.io.*;
import java.math.*;
import java.util.*;
import org.omg.CORBA.Environment;
//Codeforces
public class MainCodeforces1 {
private static MyScanner in;
private static PrintStream out;
private static boolean LOCAL_TEST = false;
public static class Visitor {
public int Size;
public int Money;
public int Index;
}
public static class VisComp implements Comparator<Visitor> {
@Override
public int compare(Visitor o1, Visitor o2) {
if (o1.Money == o2.Money)
return o1.Size - o2.Size;
else
return o2.Money - o1.Money;
}
}
public static class Table {
public int Index;
public int Size;
}
public static class TableComp implements Comparator<Table> {
@Override
public int compare(Table o1, Table o2) {
return o1.Size - o2.Size;
}
}
private static void solve() throws IOException
{
MainCodeforces1 main = new MainCodeforces1();
int nReq = in.nextInt();
ArrayList<Visitor> vis = new ArrayList<MainCodeforces1.Visitor>();
for (int i = 0; i < nReq; i++) {
Visitor v = new Visitor();
v.Size = in.nextInt();
v.Money = in.nextInt();
v.Index = i + 1;
vis.add(v);
}
Collections.sort(vis, new VisComp());
for (int i = 0; i < vis.size(); i++) {
// out.println("" + vis.get(i).Money + " - " + vis.get(i).Size);
}
int kTables = in.nextInt();
ArrayList<Table> tables = new ArrayList<MainCodeforces1.Table>();
boolean[] tblFilled = new boolean[kTables];
for (int i = 0; i < kTables; i++) {
Table tbl = new Table();
tbl.Index = i + 1;
tbl.Size = in.nextInt();
tables.add(tbl
);
}
Collections.sort(tables, new TableComp());
ArrayList<String> str = new ArrayList<String>();
int nAccepted = 0;
int sum = 0;
for (int i = 0; i < vis.size(); i++) {
Visitor v = vis.get(i);
for (int j = 0; j < tblFilled.length; j++) {
Table t = tables.get(j);
if (!tblFilled[j] && t.Size >= v.Size) {
nAccepted++;
sum += v.Money;
tblFilled[j] = true;
str.add("" + v.Index + " " + t.Index);
break;
}
}
}
out.println("" + nAccepted + " " + sum);
for (String s : str) {
out.println(s);
}
}
public static void main(String[] args) throws IOException {
// helpers for input/output
out = System.out;
try {
String cname = System.getenv("COMPUTERNAME");
if (!cname.equals(""))
LOCAL_TEST = true;
} catch (Exception e) {
}
if (LOCAL_TEST) {
in = new MyScanner("E:\\zin.txt");
}
else {
boolean usingFileForIO = false;
if (usingFileForIO) {
// using input.txt and output.txt as I/O
in = new MyScanner("input.txt");
out = new PrintStream("output.txt");
}
else {
in = new MyScanner();
out = System.out;
}
}
solve();
}
// =====================================
static class MyScanner {
BufferedReader bufReader;
StringTokenizer strTok;
public MyScanner() throws IOException
{
bufReader = new BufferedReader(new InputStreamReader(System.in));
strTok = new StringTokenizer("");
}
public MyScanner(String inputFile) throws IOException {
bufReader = new BufferedReader(new InputStreamReader(
new FileInputStream(
inputFile)));
strTok = new StringTokenizer("");
}
String GetNextToken() throws IOException {
if (!strTok.hasMoreTokens())
strTok = new StringTokenizer(bufReader.readLine());
return strTok.nextToken();
}
public int nextInt() throws IOException {
return Integer.valueOf(GetNextToken());
}
public long nextLong() throws IOException {
return Long.valueOf(GetNextToken());
}
public double nextDouble() throws IOException {
return Double.valueOf(GetNextToken());
}
public String nextString() throws IOException {
return GetNextToken();
}
public String nextLine() throws IOException {
return bufReader.readLine();
}
public int countTokens() {
return strTok.countTokens();
}
public boolean hasMoreTokens() {
return strTok.hasMoreTokens();
}
}
}
No comments:
Post a Comment