Wednesday, May 3, 2017

URI 1495 Solution Football - Solution in C++ | Ad Hoc

URI 1495 Solution Football - Solution in C++ | Ad Hoc


URI Online Judge Solution  1495 Football | Ad Hoc
URI Main Problem Link -

Problem Name: URI Problem 1495
Problem Number : URI Problem Football Solution
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution Football 1495 Code in CPP:


#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> v;

bool compare(int a, int b) { return (a > b); }

int main(int argc, char const *argv[])
{
 int n, g, s, r, c, i, sz;
 bool b;

 while(scanf("%d %d", &n, &g) == 2)
 {
  c = 0;
  v.clear();

  for (i = 0; i < n; ++i)
  {
   scanf("%d %d", &s, &r);
   if(s > r) c += 3;
   else v.push_back(s - r);
  }

  sort(v.begin(), v.end(), compare);
  sz = v.size();
  b = false;

  for (i = 0; i < sz; ++i)
  {
   if(b){
    if(v[i] == 0) c++;
    else break;
   }else{
    if(g <= 0) b = true;

    if((1 - v[i]) <= g){
     g -= (1 - v[i]);
     c += 3;
    }else if((0 - v[i]) == g){
     c++;
     g -= (0-v[i]);
    }else{
     b = true;
    }
   }
  }

  printf("%d\n", c);
 }

 return 0;
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.