Az alábbi letöltési lehetőségek közül választhatsz: (
segítség)
Típus: text/plain
Tartalmaz szöveget
Karakterkódolás: us-ascii
Méret: 1 KB
using System;
namespace Birosag
{
struct Ugy : System.IComparable
{
public int index;
public int hatarido;
public int birsag;
public int CompareTo(object obj)
{
return ((Ugy) obj).birsag - this.birsag;
}
}
class Program
{
const int Nincs = 0;
const string InputFile = "biro0.be",
OutputFile = "biro0.ki";
int N, osszBirsag = 0;
Ugy[] ugyek;
int[] napok;
private void Beolvas()
{
System.IO.StreamReader sr = new System.IO.StreamReader(InputFile);
string[] sor;
N = int.Parse(sr.ReadLine());
ugyek = new Ugy[N];
napok = new int[N];
for (int i = 0; i < N; i++) {
sor = sr.ReadLine().Split();
ugyek[i].index = i;
ugyek[i].hatarido = int.Parse(sor[0]);
ugyek[i].birsag = int.Parse(sor[1]);
napok[i] = Nincs;
}
sr.Close();
}
private void Beosztas()
{
bool talalt;
Array.Sort(ugyek);
for (int i = 0; i < N; i++) {
talalt = false;
for (int j = ugyek[i].hatarido - 1; j >= 0 && !talalt; j--) {
if (napok[j] == Nincs) {
napok[j] = ugyek[i].index + 1;
talalt = true;
}
}
if (!talalt) {
for (int j = N - 1; j >= ugyek[i].hatarido && !talalt; j--) {
if (napok[j] == Nincs) {
napok[j] = ugyek[i].index + 1;
osszBirsag += ugyek[i].birsag;
talalt = true;
}
}
}
}
}
private void Kiir()
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(OutputFile);
sw.WriteLine(osszBirsag);
for (int i = 0; i < N; i++)
sw.WriteLine(napok[i]);
sw.Close();
}
private void Indit()
{
Beolvas();
Beosztas();
Kiir();
}
static void Main(string[] args)
{
Program program = new Program();
program.Indit();
}
}
}