CodeForces 492C Vanya and Exams【Greedy】(Water Question)

Question link: https://vjudge.net/contest/194475#problem/D

 

The main idea of ​​the title:
There is a person who has n courses, and he can get at most r credits for each course. As long as the average credits of all courses have avg, he can get a scholarship. For each course, he has already obtained ai credits, and the rest For each credit, you need to write a bi thesis to get it, and then ask you, how many papers this person writes at least to get a scholarship

 

Water problems, no skills at all

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define ll long long 
ll n, r, avg;

struct node
{
    ll score, res;
}nod[100100]; ;

bool mycmp(node a, node b)
{
    return a.res < b.res;
}

intmain ()
{
    ll i, j;
    while (scanf("%lld%lld%lld", &n, &r, &avg)!= EOF)
    {
        memset(nod, 0, sizeof(nod));
        ll target = n * avg;           // Convert the average score to be achieved into the total target score to be achieved, which is better to judge 
        ll sum= 0 , ans= 0 ;
         for (i = 0 ; i < n; i++ )
        {
            scanf("%lld%lld", &nod[i].score, &nod[i].res);
            sum += nod[i].score;
        }
        if (sum >= target)
        {
            printf("0\n");
        }
        else
        {
            sort(nod, nod + n, mycmp);
            for (i = 0; i < n; i++)
            {
                if (nod[i].score == r) continue ;        // If the point is already the highest score in the subject 
                ll cur = r - nod[i].score;
                 if ((sum + cur) <= target)
                {
                    I am += why;
                    ans + = cur * nod [i] .res;
                }
                else
                {
                    ans += (target - sum)*nod[i].res;
                    sum = target;
                }
                if (sum == target)break;
            }
            printf("%lld\n", ans);
        }
    }
    return 0;
}

 

2018-04-21

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324592213&siteId=291194637