Description
小花梨点外卖,点了𝑛件商品,第𝑖件商品价值𝑣𝑖元。现在有两种满减优惠方案:
第一种:总价值大于等于𝑎元则优惠𝑏元
第二种:总价值大于等于𝑐元则优惠𝑑元
最多选择一种满减优惠,小花梨想知道最少需要花多少钱
Input
第一行输入五个正整数𝑛, 𝑎, 𝑏, 𝑐, 𝑑,含义如上
第二行输入𝑛个正整数表示𝑣𝑖
(1 ≤ 𝑛, 𝑎, 𝑏, 𝑐, 𝑑, 𝑣𝑖 ≤ 100, 𝑎 ≥ 𝑏, 𝑐 ≥ 𝑑)
Output
输出一行包含一个整数表示答案
Example
Sample Input Sample Output
5 10 5 15 10
1 2 3 4 5
5
5 20 20 30 30
1 2 3 4 5
15
5 5 5 10 5
1 2 3 4 5
10

签到题

#include <stdio.h>
#include<iostream>
#include<algorithm>
#include <string.h>
#define MAXN 10000 + 10
#define N 20
#define ll long long
using namespace std;

int main()
{
    int n,a,b,c,d;
    while(scanf("%d %d %d %d %d",&n,&a,&b,&c,&d)!=EOF)
    {
        int sum[10505]={0},f[105]={0},s=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&f[i]);
            s+=f[i];
            //f[i]+=f[i-1];
        }
        int x=s,y=s;
        if(s>=a) x=s-b;
        if(s>=c) y=s-d;
        printf("%d\n",min(x,y));
        /*int cnt=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=i;j<=n;j++)
            {
                sum[cnt++]=f[j]-f[i-1];
            }
        }
        sort(sum,sum+cnt);
        for(int i=1;i<cnt;i++)
        {
            printf("sum[%d]=%d ",i,sum[i]);
        }
        printf("\n");
        int x,y,s;
        x=upper_bound(sum,sum+cnt,a)-sum;
        y=upper_bound(sum,sum+cnt,c)-sum;
        s=min(sum[x-1]-b,sum[y-1]-c);
        printf("x=%d y=%d s=%d\n",x,y,s);
        printf("%d\n",s);*/
    }
}
/*
5 10 5 15 10
1 2 3 4 5
*/