#include "stdio.h"
#include <climits>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Potwor
{
long int a[3];
};
int main()
{
//FILE* dataIn;
//dataIn = fopen("data.in", "r");
long int t;
long int live, liveTmp;
//if(dataIn != NULL)
//{
string dodatni ="", ujemny ="", dadatniAle="";
//fscanf(dataIn, "%ld", &t);
//fscanf(dataIn, "%ld", &live);
cin >> t;
cin >>live;
liveTmp = live;
long int temp[2];
vector <Potwor> lista;
for(long int i=1; i<=t; i++)
{
//fscanf(dataIn, "%ld %ld", &temp[0], &temp[1]);
cin >>temp[0];
cin >>temp[1];
char tmp[6];
if(temp[0]>temp[1])
{
Potwor temporary;
temporary.a[0]=temp[0];
temporary.a[1]=temp[1];
temporary.a[3]=i;
lista.push_back(temporary);
}
else
{
if (liveTmp > temp[0])
{
sprintf(tmp, "%ld ",i);
dodatni+=tmp;
liveTmp = liveTmp - temp[0]+temp[1];
}
else
{
Potwor temporary;
temporary.a[0]=temp[0];
temporary.a[1]=temp[1];
temporary.a[3]=i;
lista.push_back(temporary);
}
}
live = live -temp[0]+temp[1];
}
if(live>0)
{
char tmp[6];
bool war = false, war2=false;
while(!lista.empty())
{
long int tymc;
for(long int i=0; i<lista.size(); i++)
{
if(i==0)
{
if(war)
war2=true;
war=true;
tymc = lista[0].a[0];
}
if(tymc == lista[i].a[0] && tymc == lista[i].a[0] && tymc == liveTmp && war && war2)
{
cout <<"NIE\n";
return 0;
}
if(lista[i].a[0]<liveTmp)
{
war = false;
sprintf(tmp, "%ld ",lista[i].a[3]);
dodatni+=tmp;
liveTmp = liveTmp - lista[i].a[0]+lista[i].a[1];
lista.erase(lista.begin()+i);
}
}
}
cout << "TAK\n";
cout << dodatni << dadatniAle << ujemny;
}
else
cout << "NIE\n";
//}
//fclose(dataIn);
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 | #include "stdio.h" #include <climits> #include <iostream> #include <string> #include <vector> using namespace std; struct Potwor { long int a[3]; }; int main() { //FILE* dataIn; //dataIn = fopen("data.in", "r"); long int t; long int live, liveTmp; //if(dataIn != NULL) //{ string dodatni ="", ujemny ="", dadatniAle=""; //fscanf(dataIn, "%ld", &t); //fscanf(dataIn, "%ld", &live); cin >> t; cin >>live; liveTmp = live; long int temp[2]; vector <Potwor> lista; for(long int i=1; i<=t; i++) { //fscanf(dataIn, "%ld %ld", &temp[0], &temp[1]); cin >>temp[0]; cin >>temp[1]; char tmp[6]; if(temp[0]>temp[1]) { Potwor temporary; temporary.a[0]=temp[0]; temporary.a[1]=temp[1]; temporary.a[3]=i; lista.push_back(temporary); } else { if (liveTmp > temp[0]) { sprintf(tmp, "%ld ",i); dodatni+=tmp; liveTmp = liveTmp - temp[0]+temp[1]; } else { Potwor temporary; temporary.a[0]=temp[0]; temporary.a[1]=temp[1]; temporary.a[3]=i; lista.push_back(temporary); } } live = live -temp[0]+temp[1]; } if(live>0) { char tmp[6]; bool war = false, war2=false; while(!lista.empty()) { long int tymc; for(long int i=0; i<lista.size(); i++) { if(i==0) { if(war) war2=true; war=true; tymc = lista[0].a[0]; } if(tymc == lista[i].a[0] && tymc == lista[i].a[0] && tymc == liveTmp && war && war2) { cout <<"NIE\n"; return 0; } if(lista[i].a[0]<liveTmp) { war = false; sprintf(tmp, "%ld ",lista[i].a[3]); dodatni+=tmp; liveTmp = liveTmp - lista[i].a[0]+lista[i].a[1]; lista.erase(lista.begin()+i); } } } cout << "TAK\n"; cout << dodatni << dadatniAle << ujemny; } else cout << "NIE\n"; //} //fclose(dataIn); return 0; } |
English