Codeforces 534C Polycarpus' Dice(思路)

本篇介绍了一道算法题目,玩家需根据已知的骰子总数及点数之和,推算出每个骰子无法显示的点数数量。通过计算每个骰子可能的最小与最大点数来解决此问题。
C. Polycarpus' Dice
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of the following type: dice i couldn't show number r. For example, if Polycarp had two six-faced dice and the total sum is A = 11, then Agrippina can state that each of the two dice couldn't show a value less than five (otherwise, the remaining dice must have a value of at least seven, which is impossible).

For each dice find the number of values for which it can be guaranteed that the dice couldn't show these values if the sum of the shown values is A.

Input

The first line contains two integers n, A (1 ≤ n ≤ 2·105, n ≤ A ≤ s) — the number of dice and the sum of shown values wheres = d1 + d2 + ... + dn.

The second line contains n integers d1, d2, ..., dn (1 ≤ di ≤ 106), where di is the maximum value that the i-th dice can show.

Output

Print n integers b1, b2, ..., bn, where bi is the number of values for which it is guaranteed that the i-th dice couldn't show them.

Examples
input
2 8
4 4
output
3 3 
input
1 3
5
output
4 
input
2 3
2 3
output
0 1 
Note

In the first sample from the statement A equal to 8 could be obtained in the only case when both the first and the second dice show 4. Correspondingly, both dice couldn't show values 1, 2 or 3.

In the second sample from the statement A equal to 3 could be obtained when the single dice shows 3. Correspondingly, it couldn't show 1, 2, 4 or 5.

In the third sample from the statement A equal to 3 could be obtained when one dice shows 1 and the other dice shows 2. That's why the first dice doesn't have any values it couldn't show and the second dice couldn't show 3.

题目大意:给你n个骰子,它们的点数之和为A,再给出每个骰子的最大点数,问对于每个                     骰子有多少点数是不可能出现的。
思路:不可能出现的点数等于最大点数减去可能出现的点数,所以只要求出每个骰子可出              现的最小与最大点数,用最大点数一减即可。
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1e9+10;
const int maxn = 2*1e5+10;
ll a[maxn],MIN[maxn],MAX[maxn]; //MIN[i]、MAX[i]:每个骰子的最小点数与最大点数
ll n,A,sum;

ll solve(int cur)
{
   return a[cur] - (MAX[cur] - MIN[cur] + 1); //每个骰子的最大点数减去能表示的点数即其不能表示的点数
}

int main()
{
   cin >> n >> A;
   for(int i = 0; i < n; i++){
       scanf("%I64d",&a[i]);
       sum += a[i];
   }
   if (sum < A){
      for(int i = 0; i < n; i++){
         if(i) printf(" ");
         printf("%I64d",a[i]);
      }
      printf("\n");
      return 0;
   }
   for(int i = 0; i < n; i++){
      ll yu = sum - a[i];
      if (yu >= A) MIN[i] = 1; //如果减去a[i]总和还大于等于A,那么骰子i可以直接取最小值1
      else MIN[i] = A - yu;   //否则骰子i的最小值就是 让其他所有骰子都取其最大值a[i],然后用A减去这些值所得的差
      if (n - 1 + a[i] <= A) MAX[i] = a[i]; //如果除骰子i之外其他骰子都取1,这样的和还不大于A,那么骰子i可以取其最大值a[i]
      else MAX[i] = A - (n - 1); //否则骰子i的最大值就是 让其他骰子都取1,然后用A减去这些值所得的差
   }

   for(int i = 0; i < n; i++){
      ll ans = solve(i);
      if(i) printf(" ");
      printf("%I64d",ans);
   }
   printf("\n");
}


内容概要:本文详细记录了对一个Android ARM64静态ELF文件中字符串加密机制的逆向分析过程。该ELF文件的所有字符串均被加密,无法通过常规strings命令或IDA直接识别。作者通过分析发现,加密字符串存储在.rodata段,其解密所需信息(包括密文地址、长度和16位密钥)保存在.data.rel.ro段的40字节描述符中。核心解密函数sub_10F408采用自反的双pass流密码算法,结合固定密钥KEY_TERM(由.data段24字节数据计算得出),实现字节级非线性、位置与长度相关的加密。文章还复现了完整的Python解密脚本,并揭示了该保护机制的本质为代码混淆而非强加密,最终成功批量解密全部956条字符串,暴露程序真实行为,如shell命令模板、设备标识篡改、网络重置等操作。此外,文中还提及未启用的自定义壳框架及其反dump设计。; 适合人群:具备逆向工程基础的安全研究人员、二进制分析人员及对ELF保护技术感兴趣的开发者。; 使用场景及目标:①学习ELF二进制中字符串加密的典型实现方式与逆向突破口;②掌握从结构识别、函数追踪到算法还原的完整逆向流程;③理解“绑定二进制”的完整性校验设计及其局限性;④实践编写IDAPython脚本自动化提取与解密敏感数据。; 阅读建议:此资源以实战案例驱动,不仅展示技术细节,更强调逆向思维与验证方法,建议读者结合IDA调试环境,逐步跟随文中步骤进行动态分析与算法验证,深入理解每一步的推理依据。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值