3504. 打工是不可能打工的

Deuchie

这道题就是瞅最大的天数开就好,先排序再一个个取,取完了还不行就是GameOver.

#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <functional>

uint32_t n;
uint64_t b;
uint64_t a[200000];

int main() {
    scanf("%u", &n);
    for (uint32_t i = 0; i < n; ++i) {
        scanf("%llu", &a[i]);
    }
    for (uint32_t i = 0; i < n; ++i) {
        uint64_t temp;
        scanf("%llu", &temp);
        b += temp;
    }
    std::sort(a, a + n, std::greater<uint64_t>());
    uint64_t sum = 0;
    uint32_t cnt = 0;
    for (uint32_t i = 0; i < n; ++i) {
        sum += a[i];
        ++cnt;
        if (sum >= b) {
            printf("%u\n", cnt);
            return 0;
        }
    }
    printf("Game Over!\n");
}
siyutao

要用long long 存储总的开销哦

RudiusGreyrat

long就够了

woshenaide

include

include

include

int compare (const void * a, const void * b);

int main()
{
long long earn=0,spend=0;
int n,flag=0;
scanf(“%d”,&n);
int a[n],b[n];

for(int i=0;i&lt;n;i++){
    scanf("%d",&amp;a[i]);
}

for(int i=0;i&lt;n;i++){
    scanf("%d",&amp;b[i]);
    spend+=b[i];
}

qsort(a,n,sizeof(int),compare);
for(int j=0;j&lt;n;j++){
    earn+=a[j];
    if(earn&gt;=spend){
        printf("%d",j+1);
        flag=1;
        break;
    }
}

if(flag==0){
    printf("Game Over!");
}
return 0;

}

int compare (const void * a, const void * b)
{
return (-( (int)a - (int)b ));
}

你当前正在回复 博客/题目
存在问题!